//package com.example.shiwu;
//
//import static com.example.shiwu.util.ArrayUtil.stringToDouble;
//import static com.example.shiwu.util.ContextVariable.DOWN_NAME;
//import static com.example.shiwu.util.DataParseUtil.getKVal;
//
//import android.annotation.SuppressLint;
//import android.app.ActionBar;
//import android.app.Activity;
//import android.app.AlertDialog;
//import android.content.Context;
//import android.content.DialogInterface;
//import android.content.SharedPreferences;
//import android.content.res.Resources;
//import android.database.Cursor;
//import android.database.sqlite.SQLiteDatabase;
//import android.graphics.Bitmap;
//import android.graphics.BitmapFactory;
//import android.os.Bundle;
//import android.os.Environment;
//import android.os.Handler;
//import android.os.Message;
//import android.util.Log;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.WindowManager;
//import android.widget.EditText;
//import android.widget.ImageView;
//import android.widget.ListView;
//import android.widget.PopupWindow;
//import android.widget.Spinner;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import androidx.appcompat.app.AppCompatActivity;
//
//import com.chaquo.python.PyObject;
//import com.chaquo.python.Python;
//import com.chaquo.python.android.AndroidPlatform;
//import com.example.shiwu.db.model.Alarm;
//import com.example.shiwu.db.model.Arrange;
//import com.example.shiwu.db.model.Device;
//import com.example.shiwu.db.model.Items;
//import com.example.shiwu.db.model.Sends;
//import com.example.shiwu.db.vo.MyQueue;
//import com.example.shiwu.manager.DatabaseHelper;
//import com.example.shiwu.service.AlarmService;
//import com.example.shiwu.service.ArrangeService;
//import com.example.shiwu.service.BoxEightService;
//import com.example.shiwu.service.BoxFiveService;
//import com.example.shiwu.service.BoxFourService;
//import com.example.shiwu.service.BoxNineService;
//import com.example.shiwu.service.BoxOneService;
//import com.example.shiwu.service.BoxSevenService;
//import com.example.shiwu.service.BoxSixService;
//import com.example.shiwu.service.BoxTenService;
//import com.example.shiwu.service.BoxThreeService;
//import com.example.shiwu.service.BoxTwoService;
//import com.example.shiwu.service.DeviceService;
//import com.example.shiwu.service.ItemsService;
//import com.example.shiwu.service.ReceiveVolEleService;
//import com.example.shiwu.service.SendsService;
//import com.example.shiwu.util.ArrayUtil;
//import com.example.shiwu.util.ByteUtil;
//import com.example.shiwu.util.Callback;
//import com.example.shiwu.util.ContextVariable;
//import com.example.shiwu.util.DataParseUtil;
//import com.example.shiwu.util.DateUtils;
//import com.example.shiwu.util.FileDownUtil;
//import com.example.shiwu.util.SocketMergeCallBackUtils;
//import com.example.shiwu.util.SwitchBoxUtil;
//
//import org.apache.commons.lang3.ArrayUtils;
//import org.json.JSONException;
//
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.UnsupportedEncodingException;
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.Date;
//import java.util.LinkedList;
//import java.util.List;
//import java.util.Queue;
//import java.util.Timer;
//import java.util.TimerTask;
//
//import cn.hutool.core.util.IdUtil;
//
//public class SendReceiveAddBeforDianJIActivity extends AppCompatActivity {
//
//    private DeviceService deviceService;
//    private ItemsService itemsService;
//    public ListView editSb;
//    public static TextView title_text, title_seting, send_sub_btn, send_pop_status;
//    public ImageView title_back;
//    private DatabaseHelper dbHelper;
//    public static Context myContext;
//    private TextView pop_close;
//    public int startCount = 0;
//    private EditText send_duration_val,
//            send_point_a_val, send_point_b_val, send_point_m_val, send_point_n_val, clear_all_mux_box_connect_val;
//    private Spinner send_repeat_val, send_frequency_val, send_filter_frequency_val, send_voltage_val;
//    private PopupWindow mPopWindow;
//    private SendsService sendsService;
//    private AlarmService alarmService;
//    private ArrangeService arrangeService;
////    private TextView pop_close;
//
//    private final String TAG = "SendReceiveActivity";
//    private static final String IP_ADDRESS = "ip_address";
//    private static final String CLIENT_PORT = "client_port";
//    private static final String CLIENT_MESSAGETXT = "client_msgtxt";
//
//    private SharedPreferences mSharedPreferences;
//    private SharedPreferences.Editor editor;
//
//    private static final int MSG_TIME_SEND = 1;
//    private static final int MSG_SOCKET_CONNECT = 2;
//    private static final int MSG_SOCKET_DISCONNECT = 3;
//    private static final int MSG_SOCKET_CONNECTFAIL = 4;
//    private static final int MSG_RECEIVE_DATA = 5;
//    private static final int MSG_SEND_DATA = 6;
//    private static final int MSG_SEND_DATA_BYTE = 7;
//    private static final int MSG_RECEIVE_TU_DATA = 8;
//    private static final int MSG_RECEIVE_TU_NEW_DATA = 9;
//    private static final int MSG_RECEIVE_POP_DATA = 10;
//    private static final int MSG_RECEIVE_OVER_DATA = 11;
//    private static final int MSG_RECEIVE_TOAST_DATA = 12;
//    private static final int MSG_RECEIVE_POLARIZABILITY = 13;
//    private static final int MSG_RECEIVE_FAIL_DATA = 14;
//    private TextView receive_voltage;
//    private Python py;
//    private PyObject pyobj, pyobj1, pyplot, pyobj2, pyobj3, pyobjfft;
//    private byte[] bytesData;
//    private byte[] data, data2, data3;
//    private Boolean startGater = false;
//    private Boolean myBool = false;
//    private Boolean myBool2 = false;
//    private Boolean myBool3 = false;
//    private Boolean myBool4 = false;
//    private Boolean myBool5 = false;
//    private String send_piont = "";//发射点
//    private String receive_piont = "";//接收点
//    private long timeouts = 15000;
////    private Boolean socketListenerBoo = true;
//
//    private Integer rx_voltage_data_len = 0;
//    private String simpleUUID = "";
//    private String itemsId;
//    private String sf = "";
//    private String srepeat = "";
//    private String svaltage = "";
//    private static String fileName = "";
//    private static String saveCvsFileName = "";
//    private Integer cvs_line = 0;
//    private Integer cvs_line_rms = 0;
//    private Integer rec_count_s = 0;
//    private static Integer packet_indx = 0;
//    private Integer packet_indx_111 = 0;
//    private Boolean bo1 = true;
//    private int packet_indx1 = 0;
//    private Integer old_packet_lens = 0;
//    public static int packet_indx_old = 0;
//    private static Integer packet_lens = 0;//总包数 1536倒计数到0 packet_lens=0, bak_packet_lens=512, rec_count=512 self.send("kConfirm",rec_count)
//    //private Integer bak_packet_lens = 0; //1536倒计数 bak_packet_lens=512, rec_count=512 self.send("kConfirm",rec_count)
//    private static int packet_lens_old = 0;
//    public static int toatalByte = 0;
//    private static int test_cout = 0;
//    public static String receiveDataAll = "";
//    public ArrayList<byte[]> all_byte_lis;
//    public int count_byte = 0;
//    private static String cmd_index_len = "";//消息的id 10
//    private boolean next_sta = false;
//    private boolean back_over = false; //biaoshi
//    private boolean byte_sta = false;//组装数据用，完全组装后 true
//    private View contentView;
//    private ImageView mChart1;
//    private TextView send_voltage_pop_val, send_repeat_pop_val, send_freq_pop_val, receive_duration_pop_val;
//    private String strData;//接收总数据数据，拼接完整数据后再解析
//    private StringBuffer stringBufferData;//接收总数据数据，拼接完整数据后再解析
//
//    private Boolean bl = false;
//
//    private Boolean bool = false;
//    private int loding_count = 0;
//    private int success_count = 0;
//    private int receive_packet_indx_count = 0;
//    private int abmn_indx = 0;
//    private byte[] buffer_new = new byte[1];
//    private boolean read_byte_sta = false;
//    private MyQueue queue, queueMsg, queueRmsMsg;
//    private BigDecimal resistivityVal;//装置系数K
//    private String permutationMode;//采集模式，加到CVS里
//    private Integer devtype;//采集模式0-4
//    private String deviceId;//设备ID 用于存储ALARM
//    private String alarmVal;// alarm内容
//    private Boolean alarmSta = false;// alarm状态
//    private int msg_sueecss_count = 0;
//    public static Boolean receive_one_field_sta = true;
//    public static Boolean returnSta = true;
//    public int error = 0;
//    public int indexsum = 0;
//    public int cycle = 1;
//    public int reconnectionCount = 0;//重连次数，超过10次 采集失败
//    Boolean errorCount = true;
//    Boolean headSta = false;
//    Boolean indxSta = false;
//    Boolean txvSta = false;
//    Boolean txcSta = false;
//    Boolean rxvSta = false;
//
//    //private int indx=0;
//    private String tx_voltage_data = "";
//    private String tx_current_data = "";
//    private String rx_voltage_data = "";
//    private StringBuffer rx_voltage_data1, tx_current_data1, rx_voltage_data_all1;
//    private ArrayList<String> boxLatLon;
//    private String vol_ele_noindx = "";
//    private String vol_ele = ContextVariable.vol_ele;
//    private Boolean receive_sta = false;//采集一次后true 过滤vol_ele的title
//    private int inclickGatherCount;//点击采集按钮次数
//    private ReceiveVolEleService receiveVolEleService;
//    //private SocketUtils socketUtils;
//    private static SocketMergeCallBackUtils socketUtils;
//    private String dtype, shape, abmn;
//    private String[] abmnlis = null;
//    private int dtypelen, dtypelen0, abmnLen, boxId, boxInx;
//    private String[] clearStrLisAll;
//    public static MyThread myThread;
//    public static Boolean recv_float_bool = false;
//    public int rec_count = 0;
//    public Boolean errorSta = false;
//    public static Boolean boolErr = true;
//    public Boolean recv_float_bool2 = true;
//    public Boolean anewSta = true;
//    private String rx_voltage_data_all = "";
//    private DataParseUtil dataParseUtil;
//    private ArrayList<String> alis = null;
//    private String[] boxlis = null;
//
//    private BoxOneService boxOneService;
//    private BoxTwoService boxTwoService;
//    private BoxThreeService boxThreeService;
//    private BoxFourService boxFourService;
//    private BoxFiveService boxFiveService;
//    private BoxSixService boxSixService;
//    private BoxSevenService boxSevenService;
//    private BoxEightService boxEightService;
//    private BoxNineService boxNineService;
//    private BoxTenService boxTenService;
//    private String[] freqData, modeData, freqFilterData, repeatData, valtageData;
//    private int count_44 = 0;
//    private static Boolean bl0 = false;
//    private static Boolean bl1 = false;
//    private static Boolean bl2 = false;
//    private static MyQueue myQueue = new MyQueue();
//    private static ArrayList<String> strLis = new ArrayList<>();
//    private static ArrayList<BigDecimal> txVLis = new ArrayList<BigDecimal>();
//    private static ArrayList<BigDecimal> txILis = new ArrayList<BigDecimal>();
//    private ArrayList<BigDecimal> txVLis1 = new ArrayList<BigDecimal>();
//    private ArrayList<BigDecimal> txILis1 = new ArrayList<BigDecimal>();
//    private static BigDecimal btxV, btxI, brxV;
//    private String saveTime;
//    private MyQueue queueAlarm;
//    private Queue<Byte> allBuffer;
//    private static Queue<Byte> allQueue;
//    private BigDecimal kVal;//装置系数K
//    //private ArrayList<ArrayList<BigDecimal>> VIRO = new ArrayList<ArrayList<BigDecimal>>();//电压、电流、电阻率数组用于原始数据的归一处理
//    //private ArrayList<BigDecimal> VIRO_part = null;//电压、电流、电阻率数组用于原始数据的归一处理的子集
//    private ArrayList<ArrayList<BigDecimal>> rmsAllData = new ArrayList<ArrayList<BigDecimal>>();//电压、电流、电阻率归一处理后、存储csv
//
//    private Handler mHandler = new Handler() {
//        public void handleMessage(Message msg) {
//            switch (msg.what) {
//                case MSG_TIME_SEND:
//                    break;
//
//                case MSG_RECEIVE_DATA:
//                    break;
//                case MSG_RECEIVE_TU_DATA://采集数据展示图形
//
//                    //生成的是不带-的字符串，类似于：b17f24ff026d40949c85a24f4f375d42
//                    //String simpleUUID = IdUtil.simpleUUID();
//                    String obj1 = (String) msg.obj;
//                    byte[] ios = obj1.getBytes();
//                    //String pyBytes = dataParseUtil.jb2pb(ios);
//
//                    byte[] data1 = pyobjfft.callAttr("draw_fft_square_wave", obj1, sf, rx_voltage_data_len, send_filter_frequency_val.getSelectedItemPosition()).toJava(byte[].class);
//                    mChart1.setImageBitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length));
//                    savebitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length), "niduan");
//                    savebitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length), "pailie");
//                    savebitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length), "boxing");
//                    savebitmap(BitmapFactory.decodeByteArray(data1, 0, data1.length), "pinpu");
//                    break;
//                case MSG_RECEIVE_TU_NEW_DATA:
//                    //byte[] data4 = pyobj1.callAttr("onKConfirmToMcu", rec_count_s).toJava(byte[].class);
//                    //sendByte(data4);
//                    break;
//                case MSG_RECEIVE_POP_DATA:
//                    Boolean bool = showPopupWindow();
////                    byte[] data6 = pyobj1.callAttr("onKConfirmToMcu",rec_count).toJava(byte[].class);
////                    sendByte(data6);
//                    break;
//                case MSG_RECEIVE_OVER_DATA:
//                    Toast.makeText(myContext, "采集数据结束！", Toast.LENGTH_SHORT).show();
//                    //FileDownUtil.deleteFile(DOWN_NAME + saveCvsFileName);
//                    break;
//                case MSG_RECEIVE_TOAST_DATA:
//                    send_pop_status.setText("设备告警");
//                    String msgData = (String) msg.obj;
//                    Toast.makeText(myContext, msgData, Toast.LENGTH_SHORT).show();
//                    break;
//                case MSG_RECEIVE_POLARIZABILITY:
////                    String polar = (String) msg.obj;
////                    String[] plis = polar.split(",");
////                    String polarizability = pyobjfft.callAttr("polarizability", plis[0], plis[1]).toJava(String.class);
//                    //System.out.println("--------------------polarizability-------------------- " + polarizability);
//                    String polarizability = "100";
//                    queueMsg.enQueue(polarizability + ", ");
//                    queueMsg.enQueue(permutationMode + ";");
//                case MSG_RECEIVE_FAIL_DATA:
//                    Toast.makeText(myContext, "采集数据失败！", Toast.LENGTH_SHORT).show();
//                    break;
//                default:
//                    break;
//            }
//        }
//
//        ;
//    };
//
//    private void savebitmap(Bitmap bitmap, String name) {
//
//        //创建文件，因为不存在2级目录，所以不用判断exist，要保存png，这里后缀就是png，要保存jpg，后缀就用jpg
//        File file = new File(DOWN_NAME + "/img/" + fileName + "_" + name + ".png");
//        File downloadFile = new File(ContextVariable.IMG_DOWN_NAME);
//        try {
//            if (!downloadFile.exists()) {
//                downloadFile.mkdir();
//            }
//            //文件输出流
//            FileOutputStream fileOutputStream = new FileOutputStream(file);
//            //压缩图片，如果要保存png，就用Bitmap.CompressFormat.PNG，要保存jpg就用Bitmap.CompressFormat.JPEG,质量是100%，表示不压缩
//            bitmap.compress(Bitmap.CompressFormat.PNG, 40, fileOutputStream);
//            //写入，这里会卡顿，因为图片较大
//            fileOutputStream.flush();
//            //记得要关闭写入流
//            fileOutputStream.close();
//            //成功的提示，写入成功后，请在对应目录中找保存的图片
//            //System.out.println("写入成功！目录" + Environment.getExternalStorageDirectory() + "/"+name+".png");
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//            //失败的提示
//            System.out.println("写入失败！目录" + Environment.getExternalStorageDirectory() + "/" + name + ".png");
//        } catch (IOException e) {
//            e.printStackTrace();
//            //失败的提示
//            System.out.println("写入失败！目录" + Environment.getExternalStorageDirectory() + "/" + name + ".png");
//        }
//
//    }
//
//    /**
//     * 定义文件保存的方法，写入到文件中，所以是输出流
//     */
//    public void saveFile(String[] vel, String simpleUUID) {
//
//        String content = "";
//        FileOutputStream fos = null;
//        try {
//            // Context.MODE_PRIVATE私有权限，Context.MODE_APPEND追加写入到已有内容的后面
//            fos = myContext.openFileOutput(getFileName(simpleUUID), Context.MODE_APPEND);
//            String content1 = vel[0];
//            if (!content1.equals("") && content1.length() > 0) {//cvs头
//                fos.write(content1.getBytes());
//            }
//
//            for (int i = vel.length - 1; i >= 0; i--) {//cvs数据
//                if (i > 0) {
//                    if (!vel[i].contains("\n")) {
//                        content = vel[i];
//                    } else {
//                        content = vel[i].substring(1);
//                    }
//                    fos.write(content.getBytes());
//                    fos.write("\r\n".getBytes());//写入换行
//                }
//            }
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            if (fos != null) {
//                try {
//                    fos.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }
//
//    /**
//     * get file name such as 20171031.txt
//     *
//     * @return
//     */
//    private String getFileName(String simpleUUID) {
//        Items items = findSelectItem();
//        return items.getId() + "-" + simpleUUID + ".cvs";
//    }
//
////    private void savebitmap(Bitmap bitmap) {
////
////        //创建文件，因为不存在2级目录，所以不用判断exist，要保存png，这里后缀就是png，要保存jpg，后缀就用jpg
////        File file = new File(Environment.getExternalStorageDirectory() + "/mfw.png");
////        try {
////            //文件输出流
////            FileOutputStream fileOutputStream = new FileOutputStream(file);
////            //压缩图片，如果要保存png，就用Bitmap.CompressFormat.PNG，要保存jpg就用Bitmap.CompressFormat.JPEG,质量是100%，表示不压缩
////            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
////            //写入，这里会卡顿，因为图片较大
////            fileOutputStream.flush();
////            //记得要关闭写入流
////            fileOutputStream.close();
////            //成功的提示，写入成功后，请在对应目录中找保存的图片
////            System.out.println("写入成功！目录" + Environment.getExternalStorageDirectory() + "/mfw.png");
////        } catch (FileNotFoundException e) {
////            e.printStackTrace();
////            //失败的提示
////            System.out.println("写入失败！目录" + Environment.getExternalStorageDirectory() + "/mfw.png");
////        } catch (IOException e) {
////            e.printStackTrace();
////            //失败的提示
////            System.out.println("写入失败！目录" + Environment.getExternalStorageDirectory() + "/mfw.png");
////        }
////
////    }
//
//
//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        //退出HandlerThread的Looper循环。
//        System.out.println("---------------------- onDestroy --------------------");
//        SocketMergeCallBackUtils.success_count = 0;
//        //SocketMergeCallBackUtils.buffer = null;
////        if (socketUtils != null) {
////            socketUtils.isReConnect = true;
////            socketUtils.releaseSocket();
////        }
//        if (myThread != null) {
//            myThread.interrupt();
//        }
//
//        msg_sueecss_count = 0;
//        inclickGatherCount = 0;
//        dtypelen = 0;
//        dtypelen0 = 0;
//        startGater = false;
//
//    }
//
//    public int getBoxInx() {
//        Items items = findSelectItem();
//        itemsId = items.getId().toString();
//        Arrange arrange1 = new Arrange();
//        arrange1.setItemId(Integer.valueOf(itemsId));
//        List<Arrange> arrangeLis = arrangeService.getArrange(arrange1);
//        abmnLen = arrangeLis.get(0).deviceTypeLen + 1;
//        Device device = new Device();
//        device.setItemId(itemsId);
//        List<Device> lis = deviceService.getDevice(device);
//        int count = 0;
//        if (lis.size() == 0) {
//            Toast.makeText(myContext, "网络连接失败！", Toast.LENGTH_SHORT).show();
//            //return;
//            count = 0;
//        } else if (lis.size() > 0) {
//            String box = lis.get(0).getBox().replaceAll(" ", "");
//            boxlis = box.split(",");
//            alis = new ArrayList();
//            for (int i = 0; i < boxlis.length; i++) {
//                if (!boxlis[i].equals("00")) {
//                    alis.add(boxlis[i]);
//                }
//            }
//            count = abmnLen / alis.size();
//        }
//
//        return count;
//    }
//
//    /**
//     * 解析数据包数据
//     *
//     * @param abmnlis
//     * @return
//     * @throws InterruptedException
//     * @throws IOException
//     */
//    private synchronized Boolean recv_float_array_with_indx(String[] abmnlis) throws InterruptedException, IOException {
//
//        String dateStr = DateUtils.parseYmdHmsDate();
//        int status = 0;
//        int bak_packet_lens = 0;
//        int bak_indx = 0;
//        returnSta = false;
//
//        while (recv_float_bool) {
//
//            //VIRO_part = new ArrayList<BigDecimal>();
//            bak_packet_lens = packet_lens_old / 3;
//            error = 0;
//            // 1232
//            String headStr = "";
//            if (socketUtils.socketReconnection) {
//                Log.e("socketReconnection", "-------------socketReconnection00000-----------");
//
//                return false;
//
//                //socketUtils.clrearBuffer();
//            }
//
//            //接收包头AA55
//
//            receive_one_field_sta = true;
//            byte[] str_one_field = receive_one_field("AA55");
////            if (str_one_field.length ==0){
////                continue;
////            }
//
//            //System.out.println("str_one_field head ===" + str_one_field);
//            int str_one_field_len = str_one_field.length;
//            headStr = Arrays.toString(str_one_field);
//
//            if (str_one_field_len > 0) {
//                if (str_one_field[0] == 0) {
//                    System.out.println("header len == 0" + str_one_field + " --- " + Arrays.toString(str_one_field));
//                    break;
//
//                } else if (str_one_field_len < 2) {
//                    System.out.println("header len < 2" + str_one_field + " --- " + Arrays.toString(str_one_field));
//                    error += 1;
//                    break;
//
//                } else if (str_one_field_len > 2) {
//                    error = error + 1;
//                    System.out.println("header len >2, break: " + str_one_field + " --- " + Arrays.toString(str_one_field));
//                    break;
//
//
//                } else {
//                    int header = recv_unsigned_int(str_one_field);
//                    if (header != 0xAA55) {
//                        System.out.println("header error " + new String(str_one_field) + " --- " + Arrays.toString(str_one_field));
//
//                    }
//                }
//            }
//
//
//
//            //接收包的indx
//            //需要对接收到的_receive_one_field的长度做判断，如果长度不够，就认为接收出错
//            String indexStr = "";
//            int indx = 0;
//            receive_one_field_sta = true;
//
//            byte[] str_one_field2 = receive_one_field("indx");
//            int str_one_field2_len = str_one_field2.length;
//            indexStr = Arrays.toString(str_one_field2);
//            //System.out.println("--------------------str_one_field2--------------------" + str_one_field2);
//
//
//            if (str_one_field2_len > 0) {
//                if (str_one_field2_len != 2) {
//                    error = error + 1;
//                    System.out.println("header no error 0--- " + headStr);
//                    //System.out.println("index no error 0--- " + indexStr);
//                    System.out.println("接收包的indx error1 " + new String(str_one_field2) + " --- " + Arrays.toString(str_one_field2));
//                    break;
//
//                } else {
//                    indx = recv_unsigned_int(str_one_field2);
//                    if (indx == 43605) {
//                        //System.out.println("接收包的indx 出错  " + indx);
//                    }
//                    if (errorSta) {
//                        //System.out.println("接收包的indx 出错  " + indx);
//                    } else {
//                        if (indx == 1) {
//                            //System.out.println("--------------------index new --------------------  " + indx);
//
//                        }
//                    }
//                    errorSta = false;
//                    queueMsg.enQueue(ContextVariable.freq + ", ");
//                    queueMsg.enQueue(cycle + ", ");
//                    queueMsg.enQueue(indexsum - indx + ", ");
//                    //if(devtype == 2 || devtype == 3 || devtype == 4){
//                    queueMsg.enQueue(abmnlis[0] + ", ");
//                    queueMsg.enQueue(abmnlis[1] + ", ");
//                    queueMsg.enQueue(abmnlis[2] + ", ");
//                    queueMsg.enQueue(abmnlis[3] + ", ");
//                        //VIRO_part.add(new BigDecimal(abmnlis[0]));
//                        //VIRO_part.add(new BigDecimal(abmnlis[1]));
//                        //VIRO_part.add(new BigDecimal(abmnlis[2]));
//                        //VIRO_part.add(new BigDecimal(abmnlis[3]));
////                    }else {
////                        queueMsg.enQueue(abmnlis[0] + ", ");
////                        queueMsg.enQueue(abmnlis[2] + ", ");
////                        queueMsg.enQueue(abmnlis[3] + ", ");
////                        queueMsg.enQueue(abmnlis[1] + ", ");
//                        //VIRO_part.add(new BigDecimal(abmnlis[0]));
//                        // VIRO_part.add(new BigDecimal(abmnlis[3]));
//                        //VIRO_part.add(new BigDecimal(abmnlis[1]));
//                        //VIRO_part.add(new BigDecimal(abmnlis[2]));
//                    //}
//
//                    if (indx > bak_packet_lens) {
//                        error = error + 1;
//                        //break;
//                        System.out.println("header no error 0--- " + headStr);
//                        //System.out.println("index no error 0--- " + indexStr);
//                        System.out.println("接收包的indx111 出错  " + indx + " bak_packet_lens= " + bak_packet_lens);
//                        break;
//                    }
//
//                }
//            }
//
//
//            //tx_voltage_data
//            String txvStr = "";
//            String tx_voltage1 = null;
//            Double tx_voltage2 = null;
//            int tx_voltage1_len = 0;
//
//            receive_one_field_sta = true;
//
//            byte[] str_one_field3 = receive_one_field("tx_voltage_data");
//            int str_one_field3_len = str_one_field3.length;
//            txvStr = Arrays.toString(str_one_field3);
//
//            if (str_one_field3_len > 0) {
//                tx_voltage1_len = str_one_field3_len;
//                if (str_one_field3_len != 4) {
//                    error = error + 1;
//                    //break;
//                    System.out.println("header no error 0--- " + headStr);
//                    System.out.println("tx_voltage_data error1 " + new String(str_one_field3) + " --- " + Arrays.toString(str_one_field3));
//                    break;
//                } else {
//                    tx_voltage1 = recv_float(str_one_field3);
//                    if (!tx_voltage1.equals("")) {
//                        BigDecimal bd = stringToDouble(tx_voltage1).multiply(BigDecimal.valueOf(100));
//                        //System.out.println(" --------------------tx_voltage1-------------------- " + bd);
//                        queueMsg.enQueue(bd.setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue() + ", ");
//                        txVLis.add(bd.setScale(5, BigDecimal.ROUND_HALF_UP));
//                        errorSta = false;
//                        tx_voltage2 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue();
//                        //VIRO_part.add(BigDecimal.valueOf(tx_voltage2));
//                    }
//
//                }
//            }
//
//
//            //tx_current_data
//            String txcStr = "";
//            int tx_current1_len = 0;
//            String tx_current1 = null;
//            Double tx_current2 = null;
//            BigDecimal tx_current3 = null;
//
//
//            receive_one_field_sta = true;
//            byte[] str_one_field4 = receive_one_field("tx_current_data");
//            int str_one_field4_len = str_one_field4.length;
//            txcStr = Arrays.toString(str_one_field4);
//
//            if (str_one_field4_len > 0) {
//                tx_current1_len = str_one_field4_len;
//                if (str_one_field4_len != 4) {
//                    error = error + 1;
//                    System.out.println("tx_v no error 0--- " + txvStr);
//                    System.out.println("tx_current_data error1 " + new String(str_one_field4) + " --- " + Arrays.toString(str_one_field4));
//                    break;
//
//                } else {
//                    tx_current1 = recv_float(str_one_field4);
//
//                    if (!tx_current1.equals("")) {
//                        BigDecimal bd = stringToDouble(tx_current1).multiply(BigDecimal.valueOf(1000));
//                        tx_current2 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue();
//                        tx_current3 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP);
//                        tx_current_data1.append(tx_current2 + ", ");
//                        queueMsg.enQueue(tx_current1 + ", ");
//                        txILis.add(bd.setScale(5, BigDecimal.ROUND_HALF_UP));
//                        //VIRO_part.add(BigDecimal.valueOf(tx_current2));
//                    }
//
//
//                }
//            }
//
//            //rx_voltage_data
//            String rxvStr = "";
//            int rx_voltage1_len = 0;
//            String rx_voltage1 = null;
//            Double rx_voltage2 = null;
//            BigDecimal rx_voltage3 = null;
//
//
//            int indx_end = 0;
//
//            receive_one_field_sta = true;
//            byte[] str_one_field5 = receive_one_field("rx_voltage_data");
//            int str_one_field5_len = str_one_field5.length;
//            rxvStr = Arrays.toString(str_one_field5);
//
//            if (str_one_field5_len > 0) {
//                rx_voltage1_len = str_one_field5_len;
//                if (str_one_field5_len != 4) {
//                    error = error + 1;
//
//                    System.out.println("tx_c no error 0--- " + txcStr);
//                    System.out.println("rx_voltage_data error1 " + new String(str_one_field5) + " --- " + Arrays.toString(str_one_field5));
//                    break;
//
//                } else {
//                    rx_voltage1 = recv_float(str_one_field5);
//                    if (!rx_voltage1.equals("")) {
//                        BigDecimal bd = stringToDouble(rx_voltage1).multiply(BigDecimal.valueOf(1000));
//                        //rx_voltage2 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue();
//                        //rx_voltage3 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP);
//                        BigDecimal rx_voltage4 = bd.setScale(5, BigDecimal.ROUND_HALF_UP);
//                        queueMsg.enQueue(rx_voltage1 + ", ");
//                        rx_voltage_data1.append(rx_voltage4 + ", ");
//                        //VIRO_part.add(BigDecimal.valueOf(rx_voltage2));
//                    }
//
//                }
//            }
//
//
////            if (!"".equals(rx_voltage1) && !"".equals(tx_current1)) {//极化率
////                if (rx_voltage1_len == 4 && tx_current1_len == 4) {//过滤到出错的数据
////                    String polarizability = pyobjfft.callAttr("polarizability", rx_voltage1, tx_current1).toJava(String.class);
////                    //Log.d("polarizability", "--------------------polarizability-------------------- " + polarizability);
////                    //String polarizability = "180";
////                    queueMsg.enQueue(polarizability + ", ");
////                    queueMsg.enQueue(permutationMode + ";");
////                }
////
////            }
////            if (!"".equals(rx_voltage1) && !"".equals(tx_voltage1)) {//极化率
////                if (rx_voltage1_len == 4 && tx_voltage1_len == 4) {//过滤到出错的数据
////                    String polarizability = pyobjfft.callAttr("polarizability", tx_voltage1, rx_voltage1).toJava(String.class);
////                    //Log.d("polarizability", "--------------------polarizability-------------------- " + polarizability);
////                    queueMsg.enQueue(polarizability + ", ");
////                    queueMsg.enQueue(permutationMode + ";");
////                }
////
////            }
//            if (!"".equals(rx_voltage1) && !"".equals(tx_voltage1)) {//原始数据中的极化率
//                if (rx_voltage1_len == 4 && tx_voltage1_len == 4) {//过滤到出错的数据
//
//                    //resistivityVal = getResistivity(Integer.parseInt(abmnlis[0]), Integer.parseInt(abmnlis[1]),
//                    //Integer.parseInt(abmnlis[2]), Integer.parseInt(abmnlis[3]), rx_voltage3, tx_current3);
//                    //VIRO_part.add(resistivityVal);
//                    //VIRO_part.add(kVal);
//                    //System.out.println("kVal ======= "+kVal);
//                    queueMsg.enQueue(0 + ", ");
//                    queueMsg.enQueue(permutationMode + ";");
//                    kVal = null;
//                }
//
//            }
//            //VIRO.add(VIRO_part);
//            if (error == 0) {
//
//                rec_count = rec_count + 1;
//                packet_lens -= 3;
//                if (packet_lens <= 0) {
//                    Log.e("oneOver", "--------------oneOver-------------------= " + rec_count);
//                    socketUtils.clrearBufferNew();
//                    if (bak_packet_lens == rec_count) {
//
//                        System.out.println(" =============== 4,start;11111111 结束= " + DateUtils.parseYmdHmsDate());
//
//                        recv_float_bool = false;
//                        receive_one_field_sta = false;
//
//                        if (socketUtils.socket.isClosed() == true && socketUtils.socket.isConnected() == false) {
//                            socketUtils.releaseSocketNew();
//                            rx_voltage_data1 = new StringBuffer();
//                            tx_current_data1 = new StringBuffer();
//                            rx_voltage_data_all1 = new StringBuffer();
//                        }
//                        anewSta = true;
//                        byte[] data4 = pyobj1.callAttr("onKConfirmToMcu", rec_count).toJava(byte[].class);//b'16,\x80/\x00;'
//                        if (packet_indx > 0) {
//                            packet_indx_111 = 1;
//                            Log.e("SocketClient", " ---------------------- packet_indx>0 ----------------------------");
//                            Log.e("SocketClient", " ----------------------reconnectionCount---------------------------- " + reconnectionCount);
//                            Thread.sleep(1000);
//                            // socketUtils.clrearBuffer();
//                            SocketMergeCallBackUtils.writeMsgByte16(data4, new Callback() {
//                                byte[] byAll = null;
//
//                                @Override
//                                public void onSuccess(byte[] data) {
//                                    System.out.println(" =============== 4,start data  == " + Arrays.toString(data) + " len= " + data.length);
//                                    if (data.length > 0) {
//                                        System.out.println(" =============== 4,start;2222222 结束= ------------------ data == " + Arrays.toString(data) + " len= " + data.length);
//                                        if (data[data.length - 1] != 59) {
//                                            Boolean bool = true;
//                                            byte[] bylist = new byte[1];
//                                            while (bool) {
//                                                byte buf = SocketMergeCallBackUtils.read();
//                                                bylist[0] = buf;
//                                                byte[] bytes1 = (byte[]) ArrayUtils.toPrimitive(bylist);
//                                                byAll = ArrayUtil.byteMerger(data, bytes1);
//                                                System.out.println(" 4 ------------------ alldata == " + Arrays.toString(byAll));
//                                                myBool = ReceiveDataForAnalyze1(byAll);
//                                                bool = false;
//                                                break;
//                                            }
//                                        } else {
//                                            myBool = ReceiveDataForAnalyze1(data);
//                                        }
//
//                                        Log.i("SocketClient", "Text sent successfully ============= " + Arrays.toString(byAll));
//                                        Log.i("SocketClient", "packet_indx ============= " + packet_indx);
//
//                                        anewSta = true;
//                                        System.out.println(" 重复开始1111= " + DateUtils.parseYmdHmsDate());
//                                        System.out.println("------------ bytecount 16 ==============" + socketUtils.bytecount);
//                                        socketUtils.bytecount = 0;
//                                        socketUtils.reconnection = 0;
//
//                                        new Thread(new Runnable() {
//                                            @Override
//                                            public void run() {//1 存贮原始数据 2 计算电流电压rms后放入数组和队列 在请求结束后再算重复次数的平均数 重新保存rmsCvs
//                                                saveCvs();
//                                                indexsum = 0;
//                                            }
//                                        }).start();
//                                        saveTime = DateUtils.parseYmdDate();
//                                        clearLis0();
//                                        recv_float_bool = true;
//                                        receive_one_field_sta = true;
//
//                                        //System.out.println(" 点击结束= " + DateUtils.parseYmdHmsDate());
//                                        rec_count_s = rec_count;
//                                        rec_count = 0;
//                                        back_over = true;
//                                        receive_packet_indx_count += 1;
//                                        rx_voltage_data_all1.append(rx_voltage_data1.toString() + ";");
//                                        packet_indx -= 1;
//                                        cycle += 1;
//                                        System.out.println("------------ bytecount 16 结束==============");
//                                    } else {
//                                        bo1 = false;
//                                    }
//
//                                }
//
//                                @Override
//                                public void onFailure(String errorMessage) {
//                                    Log.e("SocketClient", "Failed to send text: " + errorMessage);
//                                }
//                            });
//                            Log.e("writeMsgByte16", "writeMsgByte16 Failed to send text ==== " + bo1);
//                            if (!bo1) {
//                                bo1 = true;
//                                return false;
//                            }
//                        } else {
//                            Log.e("SocketClient", " ---------------------- packet_indx==1 ----------------------------");
//                            Log.e("SocketClient", " ----------------------reconnectionCount---------------------------- " + reconnectionCount);
//                            SocketMergeCallBackUtils.writeMsgByte(data4);
//
//                            anewSta = true;
//                            System.out.println(" 重复开始2222= " + DateUtils.parseYmdHmsDate());
//                            System.out.println("------------ bytecount ==============" + socketUtils.bytecount);
//                            socketUtils.bytecount = 0;
//
//                            new Thread(new Runnable() {
//                                @Override
//                                public void run() {
//                                    saveCvs();
////                                    saveRmsCvs();
////                                    VIRO.clear();
//                                }
//                            }).start();
//
//                            recv_float_bool = true;
//                            receive_one_field_sta = true;
//
//                            //System.out.println(" 点击结束= " + DateUtils.parseYmdHmsDate());
//                            rec_count_s = rec_count;
//                            rec_count = 0;
//                            back_over = true;
//                            receive_packet_indx_count += 1;
//                            rx_voltage_data_all1.append(rx_voltage_data1.toString() + ";");
//                            if (packet_indx == 0) {
//                                //String[] rxStrList = rx_voltage_data_all.split(";");
//                                System.out.println("------------------rx_voltage_data_all1== " + rx_voltage_data_all1.length());
//                                String[] rxStrList = rx_voltage_data_all1.toString().split(";");
//                                System.out.println("------------------rxStrList== " + rxStrList.length);
//                                String rx_voltage_data_add = ArrayUtil.strToStrArrrayAdd(rxStrList);//将string[] 做叠加处理
//                                rx_voltage_data_len = rx_voltage_data_add.substring(0, rx_voltage_data_add.length() - 1).split(",").length;
//                                if (!rx_voltage_data_add.equals("")) {
//                                    //ZloadingUtil.closeZloading(myContext);
//                                    Message msg = new Message();
//                                    msg.what = MSG_RECEIVE_TU_DATA;
//                                    msg.obj = rx_voltage_data_add;
//                                    mHandler.sendMessage(msg);
//                                }
//                                rx_voltage_data1 = new StringBuffer();
//                                tx_current_data1 = new StringBuffer();
//                                rx_voltage_data_all1 = new StringBuffer();
//                                returnSta = true;
//                                socketUtils.reconnection = 0;
//                                cycle = 1;
//                                System.out.println("---------------------重复开始 break 111------------");
//                                try {
//                                    Thread.sleep(1000);
//                                } catch (InterruptedException e) {
//                                    throw new RuntimeException(e);
//                                }
//                                break;
//                            }
//                            //返回正确确认包，
//                            rec_count = 0;
//                        }
//
//
//                    } else {
//                        status = 1;
//                        Log.e("oneOver", "--------------oneOverHandle-------------------");
//                        //errorHandle(indx);
//                        break;
//                    }
//                } else if (packet_lens > 0 && indx == 1) {
//                    //数据丢包处理，index =1 重新发送命令
//                    //errorHandle(indx);
//                    Log.e("oneOver", "--------------packet_lens > 0 && indx == 1-------------------");
//                    break;
//                }
//            }
//
//
//            //}
//            if (socketUtils.socketReconnection) {
//                Log.e("socketReconnection", "-------------socketReconnection-----------");
//                break;
//            }
//        }
//        return returnSta;
//    }
//    /**
//     * 解析数据包数据
//     *
//     * @param abmnlis
//     * @return
//     * @throws InterruptedException
//     * @throws IOException
//     */
////    private synchronized Boolean recv_float_array_with_indx(String[] abmnlis) throws InterruptedException, IOException {
////
////        String dateStr = DateUtils.parseYmdHmsDate();
////        int status = 0;
////        int bak_packet_lens = 0;
////        int bak_indx = 0;
////        returnSta = false;
////
////        while (recv_float_bool) {
////
////            //VIRO_part = new ArrayList<BigDecimal>();
////            bak_packet_lens = packet_lens_old / 3;
////            error = 0;
////            // 1232
////            String headStr = "";
////            if (socketUtils.socketReconnection) {
////                Log.e("socketReconnection", "-------------socketReconnection00000-----------");
////
////                return false;
////
////                //socketUtils.clrearBuffer();
////            }
////            if (!errorSta) {
////                //接收包头AA55
////                receive_one_field_sta = true;
////                byte[] str_one_field = receive_one_field("AA55");
////                //System.out.println("str_one_field head ===" + str_one_field);
////                int str_one_field_len = str_one_field.length;
////                headStr = Arrays.toString(str_one_field);
////
////                if (str_one_field_len > 0) {
////                    if (str_one_field[0] == 0) {
////                        System.out.println("header len error 000" + str_one_field + " --- " + Arrays.toString(str_one_field));
////                        break;
////
////                    } else if (str_one_field_len < 2) {
////                        System.out.println("header len error 1" + str_one_field + " --- " + Arrays.toString(str_one_field));
////                        error += 1;
////                        boolErr = true;
////                        indxSta = true;
////                        txvSta = true;
////                        txcSta = true;
////                        headSta = true;
////
////                    } else if (str_one_field_len > 2) {
////                        error = error + 1;
////                        boolErr = true;
////                        indxSta = true;
////                        txvSta = true;
////                        txcSta = true;
////                        headSta = true;
////                        System.out.println("header len >4, break: " + str_one_field + " --- " + Arrays.toString(str_one_field));
////                        //break;
////
////
////                    } else {
////                        int header = recv_unsigned_int(str_one_field);
////                        if (header != 0xAA55) {
////                            boolErr = true;
////                            indxSta = true;
////                            txvSta = true;
////                            txcSta = true;
////                            System.out.println("header error " + new String(str_one_field) + " --- " + Arrays.toString(str_one_field));
////
////                        }
////                    }
////                }
////
////            }
////
////            //接收包的indx
////            //需要对接收到的_receive_one_field的长度做判断，如果长度不够，就认为接收出错
////            String indexStr = "";
////            int indx = 0;
////            if (!headSta) {
////                receive_one_field_sta = true;
////
////                byte[] str_one_field2 = receive_one_field("indx");
////                int str_one_field2_len = str_one_field2.length;
////                indexStr = Arrays.toString(str_one_field2);
////                //System.out.println("--------------------str_one_field2--------------------" + str_one_field2);
////
////
////                if (str_one_field2_len > 0) {
////                    if (str_one_field2_len != 2) {
////                        error = error + 1;
////                        boolErr = true;
////                        indxSta = true;
////                        txvSta = true;
////                        txcSta = true;
////                        System.out.println("header no error 0--- " + headStr);
////                        //System.out.println("index no error 0--- " + indexStr);
////                        System.out.println("接收包的indx error1 " + new String(str_one_field2) + " --- " + Arrays.toString(str_one_field2));
////
////                    } else {
////                        indx = recv_unsigned_int(str_one_field2);
////                        if (indx == 43605) {
////                            //System.out.println("接收包的indx 出错  " + indx);
////                        }
////                        if (errorSta) {
////                            //System.out.println("接收包的indx 出错  " + indx);
////                        } else {
////                            if (indx == 1) {
////                                //System.out.println("--------------------index new --------------------  " + indx);
////
////                            }
////                        }
////                        errorSta = false;
////                        queueMsg.enQueue(ContextVariable.freq + ", ");
////                        queueMsg.enQueue(cycle + ", ");
////                        queueMsg.enQueue(indexsum - indx + ", ");
//////                        if(devtype == 2 || devtype == 3 || devtype == 4){
////                            queueMsg.enQueue(abmnlis[0] + ", ");
////                            queueMsg.enQueue(abmnlis[1] + ", ");
////                            queueMsg.enQueue(abmnlis[2] + ", ");
////                            queueMsg.enQueue(abmnlis[3] + ", ");
////                            //VIRO_part.add(new BigDecimal(abmnlis[0]));
////                            //VIRO_part.add(new BigDecimal(abmnlis[1]));
////                            //VIRO_part.add(new BigDecimal(abmnlis[2]));
////                            //VIRO_part.add(new BigDecimal(abmnlis[3]));
//////                        }else {
//////                            queueMsg.enQueue(abmnlis[0] + ", ");
//////                            queueMsg.enQueue(abmnlis[3] + ", ");
//////                            queueMsg.enQueue(abmnlis[1] + ", ");
//////                            queueMsg.enQueue(abmnlis[2] + ", ");
//////                            //VIRO_part.add(new BigDecimal(abmnlis[0]));
//////                            //VIRO_part.add(new BigDecimal(abmnlis[3]));
//////                            //VIRO_part.add(new BigDecimal(abmnlis[1]));
//////                            //VIRO_part.add(new BigDecimal(abmnlis[2]));
//////                        }
////
////                        if (indx > bak_packet_lens) {
////                            error = error + 1;
////                            boolErr = true;
////                            indxSta = true;
////                            txvSta = true;
////                            txcSta = true;
////                            //break;
////                            System.out.println("header no error 0--- " + headStr);
////                            //System.out.println("index no error 0--- " + indexStr);
////                            System.out.println("接收包的indx111 出错  " + indx + " bak_packet_lens= " + bak_packet_lens);
////
////                        }
////
////                    }
////                }
////            }
////
////            //tx_voltage_data
////            String txvStr = "";
////            String tx_voltage1 = null;
////            Double tx_voltage2 = null;
////            int tx_voltage1_len = 0;
////            if (!indxSta) {
////                receive_one_field_sta = true;
////
////                byte[] str_one_field3 = receive_one_field("tx_voltage_data");
////                int str_one_field3_len = str_one_field3.length;
////                txvStr = Arrays.toString(str_one_field3);
////
////                if (str_one_field3_len > 0) {
////                    tx_voltage1_len = str_one_field3_len;
////                    if (str_one_field3_len != 4) {
////                        error = error + 1;
////                        boolErr = true;
////                        indxSta = true;
////                        txvSta = true;
////                        txcSta = true;
////                        //break;
////                        System.out.println("header no error 0--- " + headStr);
////                        System.out.println("tx_voltage_data error1 " + new String(str_one_field3) + " --- " + Arrays.toString(str_one_field3));
////
////                    } else {
////                        tx_voltage1 = recv_float(str_one_field3);
////                        if (!tx_voltage1.equals("")) {
////                            BigDecimal bd = stringToDouble(tx_voltage1).multiply(BigDecimal.valueOf(100));
////                            //System.out.println(" --------------------tx_voltage1-------------------- " + bd);
////                            queueMsg.enQueue(bd.setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue() + ", ");
////                            txVLis.add(bd.setScale(5, BigDecimal.ROUND_HALF_UP));
////                            errorSta = false;
////                            tx_voltage2 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue();
////                            //VIRO_part.add(BigDecimal.valueOf(tx_voltage2));
////                        }
////
////                    }
////                }
////            }
////
////            //tx_current_data
////            String txcStr = "";
////            int tx_current1_len = 0;
////            String tx_current1 = null;
////            Double tx_current2 = null;
////            BigDecimal tx_current3 = null;
////            if (!txvSta) {
////
////                receive_one_field_sta = true;
////                byte[] str_one_field4 = receive_one_field("tx_current_data");
////                int str_one_field4_len = str_one_field4.length;
////                txcStr = Arrays.toString(str_one_field4);
////
////                if (str_one_field4_len > 0) {
////                    tx_current1_len = str_one_field4_len;
////                    if (str_one_field4_len != 4) {
////                        error = error + 1;
////                        boolErr = true;
////                        indxSta = true;
////                        txvSta = true;
////                        txcSta = true;
////                        System.out.println("tx_v no error 0--- " + txvStr);
////                        System.out.println("tx_current_data error1 " + new String(str_one_field4) + " --- " + Arrays.toString(str_one_field4));
////
////                    } else {
////                        tx_current1 = recv_float(str_one_field4);
////
////                        if (!tx_current1.equals("")) {
////                            BigDecimal bd = stringToDouble(tx_current1).multiply(BigDecimal.valueOf(1000));
////                            tx_current2 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue();
////                            tx_current3 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP);
////                            tx_current_data1.append(tx_current2 + ", ");
////                            queueMsg.enQueue(tx_current1 + ", ");
////                            txILis.add(bd.setScale(5, BigDecimal.ROUND_HALF_UP));
////                            //VIRO_part.add(BigDecimal.valueOf(tx_current2));
////                        }
////
////
////                    }
////                }
////            }
////            //rx_voltage_data
////            String rxvStr = "";
////            int rx_voltage1_len = 0;
////            String rx_voltage1 = null;
////            Double rx_voltage2 = null;
////            BigDecimal rx_voltage3 = null;
////            if (!txcSta) {
////
////                int indx_end = 0;
////
////                receive_one_field_sta = true;
////                byte[] str_one_field5 = receive_one_field("rx_voltage_data");
////                int str_one_field5_len = str_one_field5.length;
////                rxvStr = Arrays.toString(str_one_field5);
////
////                if (str_one_field5_len > 0) {
////                    rx_voltage1_len = str_one_field5_len;
////                    if (str_one_field5_len != 4) {
////                        error = error + 1;
////                        boolErr = true;
////                        rxvSta = true;
////
////                        System.out.println("tx_c no error 0--- " + txcStr);
////                        System.out.println("rx_voltage_data error1 " + new String(str_one_field5) + " --- " + Arrays.toString(str_one_field5));
////
////                    } else {
////                        rx_voltage1 = recv_float(str_one_field5);
////                        if (!rx_voltage1.equals("")) {
////                            BigDecimal bd = stringToDouble(rx_voltage1).multiply(BigDecimal.valueOf(1000));
////                            //rx_voltage2 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue();
////                            //rx_voltage3 = bd.abs().setScale(5, BigDecimal.ROUND_HALF_UP);
////                            BigDecimal rx_voltage4 = bd.setScale(5, BigDecimal.ROUND_HALF_UP);
////                            queueMsg.enQueue(rx_voltage1 + ", ");
////                            rx_voltage_data1.append(rx_voltage4 + ", ");
////                            //VIRO_part.add(BigDecimal.valueOf(rx_voltage2));
////                        }
////
////                    }
////                }
////
////            }
//////            if (!"".equals(rx_voltage1) && !"".equals(tx_current1)) {//极化率
//////                if (rx_voltage1_len == 4 && tx_current1_len == 4) {//过滤到出错的数据
//////                    String polarizability = pyobjfft.callAttr("polarizability", rx_voltage1, tx_current1).toJava(String.class);
//////                    //Log.d("polarizability", "--------------------polarizability-------------------- " + polarizability);
//////                    //String polarizability = "180";
//////                    queueMsg.enQueue(polarizability + ", ");
//////                    queueMsg.enQueue(permutationMode + ";");
//////                }
//////
//////            }
//////            if (!"".equals(rx_voltage1) && !"".equals(tx_voltage1)) {//极化率
//////                if (rx_voltage1_len == 4 && tx_voltage1_len == 4) {//过滤到出错的数据
//////                    String polarizability = pyobjfft.callAttr("polarizability", tx_voltage1, rx_voltage1).toJava(String.class);
//////                    //Log.d("polarizability", "--------------------polarizability-------------------- " + polarizability);
//////                    queueMsg.enQueue(polarizability + ", ");
//////                    queueMsg.enQueue(permutationMode + ";");
//////                }
//////
//////            }
////            if (!"".equals(rx_voltage1) && !"".equals(tx_voltage1)) {//原始数据中的极化率
////                if (rx_voltage1_len == 4 && tx_voltage1_len == 4) {//过滤到出错的数据
////
////                    //resistivityVal = getResistivity(Integer.parseInt(abmnlis[0]), Integer.parseInt(abmnlis[1]),
////                            //Integer.parseInt(abmnlis[2]), Integer.parseInt(abmnlis[3]), rx_voltage3, tx_current3);
////                    //VIRO_part.add(resistivityVal);
////                    //VIRO_part.add(kVal);
////                    //System.out.println("kVal ======= "+kVal);
////                    queueMsg.enQueue(0 + ", ");
////                    queueMsg.enQueue(permutationMode + ";");
////                    kVal = null;
////                }
////
////            }
////            //VIRO.add(VIRO_part);
////            if (error == 0) {
////
////                rec_count = rec_count + 1;
////                packet_lens -= 3;
////                if (packet_lens <= 0) {
////                    Log.e("oneOver", "--------------oneOver-------------------= " + rec_count);
////                    socketUtils.clrearBufferNew();
////                    if (bak_packet_lens == rec_count) {
////
////                        System.out.println(" =============== 4,start;11111111 结束= " + DateUtils.parseYmdHmsDate());
////
////                        recv_float_bool = false;
////                        receive_one_field_sta = false;
////
////                        if (socketUtils.socket.isClosed() == true && socketUtils.socket.isConnected() == false) {
////                            socketUtils.releaseSocketNew();
////                            rx_voltage_data1 = new StringBuffer();
////                            tx_current_data1 = new StringBuffer();
////                            rx_voltage_data_all1 = new StringBuffer();
////                        }
////                        anewSta = true;
////                        byte[] data4 = pyobj1.callAttr("onKConfirmToMcu", rec_count).toJava(byte[].class);//b'16,\x80/\x00;'
////                        if (packet_indx > 0) {
////                            packet_indx_111 = 1;
////                            Log.e("SocketClient", " ---------------------- packet_indx>0 ----------------------------");
////                            Log.e("SocketClient", " ----------------------reconnectionCount---------------------------- " + reconnectionCount);
////                            Thread.sleep(1000);
////                            // socketUtils.clrearBuffer();
////                            SocketMergeCallBackUtils.writeMsgByte16(data4, new Callback() {
////                                byte[] byAll = null;
////
////                                @Override
////                                public void onSuccess(byte[] data) {
////                                    System.out.println(" =============== 4,start data  == " + Arrays.toString(data) + " len= " + data.length);
////                                    if (data.length > 0) {
////                                        System.out.println(" =============== 4,start;2222222 结束= ------------------ data == " + Arrays.toString(data) + " len= " + data.length);
////                                        if (data[data.length - 1] != 59) {
////                                            Boolean bool = true;
////                                            byte[] bylist = new byte[1];
////                                            while (bool) {
////                                                byte buf = SocketMergeCallBackUtils.read();
////                                                bylist[0] = buf;
////                                                byte[] bytes1 = (byte[]) ArrayUtils.toPrimitive(bylist);
////                                                byAll = ArrayUtil.byteMerger(data, bytes1);
////                                                System.out.println(" 4 ------------------ alldata == " + Arrays.toString(byAll));
////                                                myBool = ReceiveDataForAnalyze1(byAll);
////                                                bool = false;
////                                                break;
////                                            }
////                                        } else {
////                                            myBool = ReceiveDataForAnalyze1(data);
////                                        }
////
////                                        Log.i("SocketClient", "Text sent successfully ============= " + Arrays.toString(byAll));
////                                        Log.i("SocketClient", "packet_indx ============= " + packet_indx);
////
////                                        anewSta = true;
////                                        System.out.println(" 重复开始1111= " + DateUtils.parseYmdHmsDate());
////                                        System.out.println("------------ bytecount 16 ==============" + socketUtils.bytecount);
////                                        socketUtils.bytecount = 0;
////                                        socketUtils.reconnection = 0;
////
////                                        new Thread(new Runnable() {
////                                            @Override
////                                            public void run() {//1 存贮原始数据 2 计算电流电压rms后放入数组和队列 在请求结束后再算重复次数的平均数 重新保存rmsCvs
////                                                saveCvs();
////                                                indexsum = 0;
////                                            }
////                                        }).start();
////                                        saveTime = DateUtils.parseYmdDate();
////                                        clearLis0();
////                                        recv_float_bool = true;
////                                        receive_one_field_sta = true;
////
////                                        //System.out.println(" 点击结束= " + DateUtils.parseYmdHmsDate());
////                                        rec_count_s = rec_count;
////                                        rec_count = 0;
////                                        back_over = true;
////                                        receive_packet_indx_count += 1;
////                                        rx_voltage_data_all1.append(rx_voltage_data1.toString() + ";");
////                                        packet_indx -= 1;
////                                        cycle += 1;
////                                        System.out.println("------------ bytecount 16 结束==============");
////                                    } else {
////                                        bo1 = false;
////                                    }
////
////                                }
////
////                                @Override
////                                public void onFailure(String errorMessage) {
////                                    Log.e("SocketClient", "Failed to send text: " + errorMessage);
////                                }
////                            });
////                            Log.e("writeMsgByte16", "writeMsgByte16 Failed to send text ==== " + bo1);
////                            if (!bo1) {
////                                bo1 = true;
////                                return false;
////                            }
////                        } else {
////                            Log.e("SocketClient", " ---------------------- packet_indx==1 ----------------------------");
////                            Log.e("SocketClient", " ----------------------reconnectionCount---------------------------- " + reconnectionCount);
////                            SocketMergeCallBackUtils.writeMsgByte(data4);
////
////                            anewSta = true;
////                            System.out.println(" 重复开始2222= " + DateUtils.parseYmdHmsDate());
////                            System.out.println("------------ bytecount ==============" + socketUtils.bytecount);
////                            socketUtils.bytecount = 0;
////
////                            new Thread(new Runnable() {
////                                @Override
////                                public void run() {
////                                    saveCvs();
//////                                    saveRmsCvs();
//////                                    VIRO.clear();
////                                }
////                            }).start();
////
////                            recv_float_bool = true;
////                            receive_one_field_sta = true;
////
////                            //System.out.println(" 点击结束= " + DateUtils.parseYmdHmsDate());
////                            rec_count_s = rec_count;
////                            rec_count = 0;
////                            back_over = true;
////                            receive_packet_indx_count += 1;
////                            rx_voltage_data_all1.append(rx_voltage_data1.toString() + ";");
////                            if (packet_indx == 0) {
////                                //String[] rxStrList = rx_voltage_data_all.split(";");
////                                System.out.println("------------------rx_voltage_data_all1== " + rx_voltage_data_all1.length());
////                                String[] rxStrList = rx_voltage_data_all1.toString().split(";");
////                                System.out.println("------------------rxStrList== " + rxStrList.length);
////                                String rx_voltage_data_add = ArrayUtil.strToStrArrrayAdd(rxStrList);//将string[] 做叠加处理
////                                rx_voltage_data_len = rx_voltage_data_add.substring(0, rx_voltage_data_add.length() - 1).split(",").length;
////                                if (!rx_voltage_data_add.equals("")) {
////                                    //ZloadingUtil.closeZloading(myContext);
////                                    Message msg = new Message();
////                                    msg.what = MSG_RECEIVE_TU_DATA;
////                                    msg.obj = rx_voltage_data_add;
////                                    mHandler.sendMessage(msg);
////                                }
////                                rx_voltage_data1 = new StringBuffer();
////                                tx_current_data1 = new StringBuffer();
////                                rx_voltage_data_all1 = new StringBuffer();
////                                returnSta = true;
////                                socketUtils.reconnection = 0;
////                                cycle = 1;
////                                System.out.println("---------------------重复开始 break 111------------");
////                                try {
////                                    Thread.sleep(1000);
////                                } catch (InterruptedException e) {
////                                    throw new RuntimeException(e);
////                                }
////                                break;
////                            }
////                            //返回正确确认包，
////                            rec_count = 0;
////                        }
////
////
////                    } else {
////                        status = 1;
////                        Log.e("oneOver", "--------------oneOverHandle-------------------");
////                        errorHandle(indx);
////                    }
////                } else if (packet_lens > 0 && indx == 1) {
////                    //数据丢包处理，index =1 重新发送命令
////                    errorHandle(indx);
////                }
////            } else {
////                System.out.println(" 数据解析出错 ====================== " + DateUtils.parseYmdHmsDate());
////
////                Boolean bl1 = false;
////                Boolean bl2 = false;
////                Thread.sleep(1000);
////                while (boolErr) {
////                    receive_one_field_sta = false;
////
////                    byte tmp = socketUtils.read();
////                    if (String.valueOf(tmp).equals("85")) {
////                        System.out.println("tmp ===" + tmp);
////                        bl1 = true;
////                        continue;
////                    }
////                    if (bl1) {
////                        if (String.valueOf(tmp).equals("-86")) {
////                            System.out.println("tmp2 ===" + tmp);
////                            bl2 = true;
////                            bl1 = false;
////                            continue;
////                        }
////                    }
////                    if (bl2) {
////                        System.out.println("tmp3 ===" + tmp);
////                        rec_count = rec_count + 1;
////                        packet_lens -= 3;
////                        boolErr = false;
////                        bl2 = false;
////                        // receive_one_field_sta = true;
////                        errorSta = true;
////                        headSta = false;
////                        indxSta = false;
////                        txvSta = false;
////                        txcSta = false;
////                        rxvSta = false;
////                        error = 0;
////                        break;
////
////                    }
////                }
////                System.out.println("tmp333333333333333333333333333333333333333 ===");
////                socketUtils.clrearBuffer();
////                Thread.sleep(1000);
////                socketUtils.clrearBuffer();
////                Thread.sleep(500);
////                socketUtils.clrearBuffer();
////                //return false;
////                break;
////            }
////
////
////            //}
////            if (socketUtils.socketReconnection) {
////                Log.e("socketReconnection", "-------------socketReconnection-----------");
////                break;
////            }
////        }
////        return returnSta;
////    }
//
//    /**
//     * 1装置系数计算
//     * 2电阻率计算
//     */
//    private BigDecimal getResistivity(int A, int B, int M, int N, BigDecimal rxV, BigDecimal txI) {
//        // 直接使用 Math.PI 获取圆周率
//        double piValue = Math.PI;
//        kVal = getKVal(A, B, M, N);
//
//
//        BigDecimal resistivityVal = kVal.multiply(rxV.divide(txI, 5, RoundingMode.HALF_UP)).setScale(5, RoundingMode.HALF_UP);
//        return resistivityVal;
//    }
//
//    private void errorHandle(Integer indx) throws InterruptedException, IOException {
//        System.out.println("------------ bytecount error ==============" + socketUtils.bytecount + "--" + packet_lens + "--" + indx);
//        socketUtils.bytecount = 0;
//        rx_voltage_data1 = new StringBuffer();
//        tx_current_data1 = new StringBuffer();
//        rx_voltage_data_all1 = new StringBuffer();
//        errorSta = false;
//        headSta = false;
//        indxSta = false;
//        txvSta = false;
//        txcSta = false;
//        rxvSta = false;
//        errorCount = false;
//        anewSta = false;
//        error = 0;
//        returnSta = false;
//        rec_count = 0;
//        packet_lens = packet_lens_old;
//        queueMsg.clear();
//        Thread.sleep(1000);
//
//        socketUtils.clrearBuffer();
//
//        byte[] data4 = pyobj1.callAttr("onKReSync", packet_indx).toJava(byte[].class);//b'17,\x04/\x00;'
//        SocketMergeCallBackUtils.writeMsgByte(data4, new Callback() {
//            @Override
//            public void onSuccess(byte[] data) throws IOException {
//                Log.i("SocketClient", "Text sent successfully 17============= " + new String(data));
//                String msg = new String(data);
//                if (!msg.equals("")) {
//                    Boolean bl1 = getStatus(msg);
//                    if (bl1) {
//                        Boolean bool = true;
//                        List<Byte> bylist = new ArrayList<Byte>();
//                        while (bool) {
//                            byte buf = SocketMergeCallBackUtils.read();
//                            //Log.e("SocketClient 17", "Text sent successfully 17 byte ============= " + buf);
//
//                            if (buf != 59) {
//                                bylist.add(buf);
//                                if (bylist.size() > 1) {
//                                    if (bylist.get(0) == bylist.get(1)) {
//                                        if (bylist.get(0) == 0) {
//                                            bool = false;
//                                            break;
//                                        }
//                                    }
//                                }
//
//                            } else {
//                                bylist.add(buf);
//                                byte[] bytes = ArrayUtil.listTobyte(bylist);
//                                Boolean myBool = ReceiveDataForAnalyze1(bytes);
//                                bool = false;
//                                break;
//                            }
//                        }
//                    } else {
//                        Log.i("SocketClient", "Text sent successfully 17 222 ============= " + new String(data));
//                        socketUtils.clrearBuffer();
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(String errorMessage) {
//                Log.e("SocketClient", "Failed to send text 17: " + errorMessage);
//            }
//        });
//        //System.out.println(" 数据丢包，重复开始= " + DateUtils.parseYmdHmsDate());
//        Log.e(" error  ", "------数据丢包，重复开始-----" + DateUtils.parseYmdHmsDate());
//    }
//
//    private static boolean putDataToMyQueue1(byte queue) {
//        //queue = new MyQueue();
//        Boolean queuesta = true;
//        while (queuesta) {
//            //byte tmp = socketUtils.read();
//            byte tmp = queue;
//            try {
//                myQueue.enQueue(tmp);
//                Thread.sleep(10);
//
//                if (String.valueOf(tmp).equals("85")) {
//                    strLis.add("\r\n");
//                    //System.out.println("tmp ===" + tmp);
//                    strLis.add(String.valueOf(tmp));
//                    bl1 = true;
//                    break;
//                }
//                if (bl1) {
//                    if (String.valueOf(tmp).equals("-86")) {
//                        //System.out.println("tmp2 ===" + tmp);
//                        strLis.add(String.valueOf(tmp));
//                        bl2 = true;
//                        bl1 = false;
//                        break;
//                    }
//                }
//                if (bl2) {
//                    if (String.valueOf(tmp).equals("44")) {
//                        bl0 = true;
//                        queuesta = false;
//                        strLis.add(String.valueOf(tmp));
//                        break;
//                    } else {
//                        strLis.add(String.valueOf(tmp));
//                        break;
//                    }
//
//                }
//
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//            strLis.add(String.valueOf(tmp));
//
//        }
//        strLis.clear();
//        return bl0;
//    }
//
//    private static void clearLis0() {
//        txVLis.clear();
//        txILis.clear();
//        //rxVLis.clear();
//    }
//
//    private void clearLis() {
//        txVLis.clear();
//        txILis.clear();
//        txVLis1.clear();
//        txILis1.clear();
//    }
//
//    public static void set_send_pop_status() {
//        send_pop_status.setText("采集失败");
//    }
//
//    public static void main(String[] args) {
//        String str = "0.2883838382828282";
//        BigDecimal bd = stringToDouble(str);
//        BigDecimal bd1 = bd.multiply(BigDecimal.valueOf(100));
//        System.out.println(bd1);
//    }
//
//
//    //保存数据到CVS文件
//    public synchronized void saveCvs() {
//        String fileNames = fileName + "_" + permutationMode + "_" + saveTime + ".cvs";
//        saveCvsFileName = fileNames;
//        Boolean bl = FileDownUtil.MakeFile(fileName);
//        if (FileDownUtil.readFileSize(fileNames) == 1) {
//            FileDownUtil.GZIPFile(fileName, fileNames);
//        }
//        int len = queueMsg.QueueLength() / 12;
//        String[] vel = new String[len];
//        String[] velLisnew = new String[len];
//        //int ii = 0;
//        for (int i = 0; i < len; i++) {
//            //ii+=1;
//            StringBuffer val = new StringBuffer();
//            for (int j = 0; j < 12; j++) {
//                val.append(queueMsg.deQueue().toString());
//            }
//
//            vel[i] = val.toString().replace(";", "\n");
////            String[] velLis = vel[i].toString().split(",");
////            for (int j = 0; j < velLis.length; j++) {
////                if(j==3 || j==4 || j==5 || j==6){
////                    velLis[j] = boxLatLon.get(Integer.parseInt(velLis[j]) - 1);
////                }
////            }
////            String velStr = String.join(",", velLis);
////            velLisnew[i] = velStr+"\n";
//        }
//        System.out.println("queueMsg.len = "+queueMsg.QueueLength());
//        Integer cvs_line_count = FileDownUtil.saveFileNew(myContext, vel, fileNames, cvs_line, fileName);
//        cvs_line = cvs_line_count;
//
//    }
//
//    //保存数据到CVS文件
////    public synchronized void saveRmsCvs() {
////        String fileNames = "RMS_" + fileName + "_" + permutationMode + "_" + saveTime + ".csv";
////        String[] rowVal = null;
////        Integer cvs_line_count = 0;
////        if (dtypelen0 == 1) {
////            rowVal = ContextVariable.vol_rms_ele.split("");
////            cvs_line_count = FileDownUtil.saveFileNew(myContext, rowVal, fileNames, cvs_line, fileName);
////            rowVal = dataNormaliza(convertTo2DArray(VIRO));
////            cvs_line_count = FileDownUtil.saveFileNew(myContext, rowVal, fileNames, cvs_line, fileName);
////        } else {
////            rowVal = dataNormaliza(convertTo2DArray(VIRO));
////            cvs_line_count = FileDownUtil.saveFileNew(myContext, rowVal, fileNames, cvs_line, fileName);
////        }
////        //msAllData.add(pyObject);
////        cvs_line = cvs_line_count;
////    }
//
//    /**
//     * 将List<List<BigDecimal>>转换为BigDecimal[][]
//     */
//    public static BigDecimal[][] convertTo2DArray(ArrayList<ArrayList<BigDecimal>> list) {
//        if (list == null) {
//            return null;
//        }
//
//        // 创建二维数组，行数为list的大小
//        BigDecimal[][] array = new BigDecimal[list.size()][];
//
//        // 遍历list的每个元素（即每行）
//        for (int i = 0; i < list.size(); i++) {
//            List<BigDecimal> row = list.get(i);
//            if (row != null) {
//                // 将每行转换为数组
//                //array[i] = new String[]{Arrays.toString(row.toArray(new BigDecimal[0]))};
////                array[i] = row.stream()
////                        .map(BigDecimal::toPlainString)
////                        .collect(Collectors.toList()).toArray(new String[0]);
//                array[i] = row.toArray(new BigDecimal[0]);
//                //System.out.println(array[i]);
//            } else {
//                // 如果行为null，则该行设为null
//                array[i] = null;
//            }
//        }
//
//        return array;
//    }
//
//    //保存数据到CVS文件
//    public synchronized void saveRmsCvsOld() {
//        String fileNames = "RMS_" + fileName + "_" + permutationMode + "_" + saveTime + ".cvs";
//        if (FileDownUtil.readRmsFileSize(fileNames) == 1) {
//            FileDownUtil.GZIPRmsFile(fileName, fileNames);
//        }
//
//        int len = queueRmsMsg.QueueLength() / 10;
//        String[] vel = new String[len];
//        String[] velLisnew = new String[len];
//        //int ii = 0;
//        for (int i = 0; i < len; i++) {
//            //ii+=1;
//            StringBuffer val = new StringBuffer();
//            for (int j = 0; j < 10; j++) {
//                val.append(queueRmsMsg.deQueue().toString());
//            }
//
//            vel[i] = val.toString().replace(";", "\n");
////            String[] velLis = vel[i].toString().split(",");
////            for (int j = 0; j < velLis.length; j++) {
////                if(j==3 || j==4 || j==5 || j==6){
////                    velLis[j] = boxLatLon.get(Integer.parseInt(velLis[j]) - 1);
////                }
////            }
////            String velStr = String.join(",", velLis);
////            velLisnew[i] = velStr+"\n";
//        }
//
//        Integer cvs_line_count = FileDownUtil.saveFileRms(myContext, vel, fileNames, cvs_line_rms, fileName);
//        cvs_line_rms = cvs_line_count;
//
//    }
//
//    //保存buffer数据到CVS文件
//    public static synchronized void saveBufferDataForTxt(String buffer, String dateStr) {
//
//        Boolean cvs_sta = saveFileNew(myContext, buffer, dateStr + "example.txt");
////        System.out.println("===== txt文件写入成功 ===== ");
////        System.out.println(buffer);
//
//    }
//
//    /**
//     * 定义文件保存的方法，写入到文件中，所以是输出流
//     */
//    public static Boolean saveFileNew(Context context, String vel, String name) {
//        boolean bl = false;
//        FileOutputStream fos = null;
//        try {
//            // Context.MODE_PRIVATE私有权限，Context.MODE_APPEND追加写入到已有内容的后面
//            fos = context.openFileOutput(name, Context.MODE_APPEND);
//            fos.write(vel.getBytes());
//            //fos.write("\r\n".getBytes());//写入换行
//            bl = true;
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            if (fos != null) {
//                try {
//                    fos.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//        return bl;
//    }
//
//    private synchronized void receive_data() throws InterruptedException, IOException {
//
//        int count = 0;
//        while (SocketMergeCallBackUtils.bmInputStream.available() > 0) {
//            byte[] bufferAll = new byte[120 * 1024];
//            int countNew = SocketMergeCallBackUtils.bmInputStream.read(bufferAll);
//            count += countNew;
//            byte[] bufferNew = new byte[countNew];
//            System.arraycopy(bufferAll, 0, bufferNew, 0, countNew);
//            //Log.e("data","buffer00000 = "+countNew);
//            convertByteArrayToQueue(bufferNew);
//            //Log.e("data","buffer000 = "+allQueue.size());
//            Thread.sleep(1000);
//        }
//        //String str = "85, -86, 44, 100, 28, 44, 42, 107, -43, 62, 44, -128, 125, -56, -71, 44, 47, 0, -95, 45, 57, 44, 85, -86, 44, 99, 28, 44, 41, 41, -41, 62, 44, ";
//        Log.e("data", "buffer = " + allQueue.size());
//
//
//    }
//
//    public static void convertByteArrayToQueue(byte[] byteArray) {
//
//        for (byte b : byteArray) {
//            //SocketMergeCallBackUtils.putDataToMyQueue(b);//存储字节数据
//            allQueue.add(b);
//        }
//        //return allQueue;
//    }
//
//    private synchronized byte[] receive_one_field(String name) throws InterruptedException {
//        Boolean escaped = false;
//        Boolean command_sep_found = false;
//        ArrayList<Byte> one_field = new ArrayList<Byte>();
//        while (receive_one_field_sta) {
//            Byte tmp = socketUtils.read();
//            //byte tmp = allQueue.poll();
////            new Thread(new Runnable() {
////                @Override
////                public void run() {
////                    SocketMergeCallBackUtils.putDataToMyQueue(tmp);//存储字节数据
////                }
////            }).start();
//
////            if (tmp == null){
////                break;
////            }
//
//
//
//            if (escaped) {
//                if (tmp == 44 || tmp == 59 || tmp == 47) {
//                    one_field.add(tmp);
//                    escaped = false;
////                    if(tmp == 59){
////                        SocketMergeCallBackUtils.count59 += 1;
////                    }
//                } else {
//                    //one_field.add((byte) 47);
//                    one_field.add(tmp);
//                    escaped = false;
//                }
//            } else {
//                if (tmp == 47) {
//                    //遇到 / 就escaped = True 继续循环
//                    escaped = true;
//                } else if (tmp == 44) {
//                    break;
//                } else if (tmp == 59) {
//                    command_sep_found = true;
//                    break;
//                }
//
////                else if (tmp == null){
////                    break;
////                }
//                else {
//                    one_field.add(tmp);
//                }
//            }
//        }
//        byte[] bytes = ArrayUtil.listTobyte(one_field);
//        receive_one_field_sta = false;
//        return bytes;
//    }
//
//
//    private Integer recv_unsigned_int(byte[] val) {
//
//        return DataParseUtil.recv_unsigned_int(val);
//    }
//
//    private String recv_float(byte[] val) {
//        return DataParseUtil.recv_float(val);
//    }
//
//
//    @SuppressLint("MissingInflatedId")
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//
//        dataParseUtil = new DataParseUtil();
//        try {
//            Thread.sleep(1000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
//        //DataJIxi.mains();
//        // 读取内部存储沙盒文件列表
////        List<File> internalFiles = getInternalFilesNew(this,"1-78ba73d4406048bd98de17b27d459848");
////        // 将 File 对象转换为文件名（String）
////        String[] fileNames = internalFiles.stream()
////                .map(File::getName)         // 获取文件名
////                // 或 .map(File::getPath)   // 获取完整路径
////                .toArray(String[]::new);    // 转换为 String 数组
////        Log.d(TAG, "内部文件: " + internalFiles.toString());
//
//
////        try {
//        //FileDownUtil.mergeByConcatenate(fileNames,DOWN_NAME+"1-78ba73d4406048bd98de17b27d459848/allgz.gz");
////        } catch (IOException e) {
////            throw new RuntimeException(e);
////        }
//        //Boolean bool2 = FileDownUtil.downLoadFile(this,DOWN_NAME+"1-78ba73d4406048bd98de17b27d459848/allgz.gz","1-78ba73d4406048bd98de17b27d459848.gz","jingyuantest");//RMS数据
//
//        dbHelper = new DatabaseHelper(this);
//        initService();
//        queueAlarm = new MyQueue();
//        allQueue = new LinkedList<>();
//        setContentView(R.layout.send_receive_add);
//        arrangeService = new ArrangeService();
//        myContext = this;
//        all_byte_lis = new ArrayList<byte[]>();
//        stringBufferData = new StringBuffer();
//        title_back = findViewById(R.id.title_back);
//        title_text = findViewById(R.id.title_text);
//        title_seting = findViewById(R.id.title_setting);
//        title_text.setText("发射接收信息");
//
//        title_seting.setVisibility(View.INVISIBLE);
//        receive_voltage = findViewById(R.id.receive_voltage_val);
//
//        send_sub_btn = findViewById(R.id.send_sub_btn);
//        deviceService = new DeviceService();
//        itemsService = new ItemsService();
//        SharedPreferences sp = this.getSharedPreferences(this.getPackageName(), Activity.MODE_PRIVATE);
//        String ips = sp.getString("ip", "");
//        initTextView();
//        initData();
//
//        //HexBinary();
//        Resources res = getResources();
//        freqData = res.getStringArray(R.array.freqData);
//        modeData = res.getStringArray(R.array.modeData);
//        repeatData = res.getStringArray(R.array.repeatCount);
//        valtageData = res.getStringArray(R.array.valtageData);
//        queue = new MyQueue();
//        queueMsg = new MyQueue();
//        queueRmsMsg = new MyQueue();
//        mSharedPreferences = getSharedPreferences("setting", Context.MODE_PRIVATE);
//
//        rx_voltage_data1 = new StringBuffer();
//        tx_current_data1 = new StringBuffer();
//        rx_voltage_data_all1 = new StringBuffer();
//        boxId = getBoxInx();
//
////        try {
////            test_recv_float_array_with_indx();
////        } catch (InterruptedException e) {
////            throw new RuntimeException(e);
////        } catch (IOException e) {
////            throw new RuntimeException(e);
////        }
//        //获取保存的ip地址、客户端端口号
//        //mIpAddress = mSharedPreferences.getString(IP_ADDRESS, null);
//        //mClientPort = mSharedPreferences.getInt(CLIENT_PORT, DEFAULT_PORT);
//        title_back.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                SendReceiveAddBeforDianJIActivity.this.finish();
//            }
//        });
//
//        send_sub_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                try {
//                    getTexts();
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
//            }
//        });
//
//
//        try {
//            initPython(this);
//            //NetWorkUtil.getApIpAddress2();
//            //pyMain();
//        } catch (JSONException e) {
//            throw new RuntimeException(e);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//
//    @Override
//    public void onBackPressed() {
//        super.onBackPressed();
//    }
//
//    private void initTextView() {
//        send_voltage_val = findViewById(R.id.send_voltage_val);
//        send_repeat_val = findViewById(R.id.send_repeat_val);
//        send_frequency_val = findViewById(R.id.send_frequency_val);
//        send_filter_frequency_val = findViewById(R.id.send_filter_frequency_val);
//        //send_duration_val = findViewById(R.id.send_duration_val);
////        clear_all_mux_box_connect_val = findViewById(R.id.clear_all_mux_box_connect_val);
//    }
//
//    private void initService() {
//        boxOneService = new BoxOneService();
//        boxTwoService = new BoxTwoService();
//        boxThreeService = new BoxThreeService();
//        boxFourService = new BoxFourService();
//        boxFiveService = new BoxFiveService();
//        boxSixService = new BoxSixService();
//        boxSevenService = new BoxSevenService();
//        boxEightService = new BoxEightService();
//        boxNineService = new BoxNineService();
//        boxTenService = new BoxTenService();
//        Items items = findSelectItem();
//        itemsId = items.getId().toString();
//        //boxLatLon
//        List<String> lisBoxOne = performJoinQuery(itemsId, "tb_boxOne");
//        List<String> lisBoxTwo = performJoinQuery(itemsId, "tb_boxTwo");
//        List<String> lisBoxThree = performJoinQuery(itemsId, "tb_boxThree");
//        List<String> lisBoxFour = performJoinQuery(itemsId, "tb_boxFour");
//        List<String> lisBoxFive = performJoinQuery(itemsId, "tb_boxFive");
//        List<String> lisBoxSix = performJoinQuery(itemsId, "tb_boxSix");
//        List<String> lisBoxSeven = performJoinQuery(itemsId, "tb_boxSeven");
//        List<String> lisBoxEight = performJoinQuery(itemsId, "tb_boxEight");
//        List<String> lisBoxNine = performJoinQuery(itemsId, "tb_boxNine");
//        List<String> lisBoxTen = performJoinQuery(itemsId, "tb_boxTen");
//        if (lisBoxOne.size() > 0) {
//            boxLatLon = new ArrayList<>();
//            String[] str = lisBoxOne.toArray(new String[0]);
//            for (String item : str) {
//                boxLatLon.add(item);
//            }
//        }
//        System.out.println("------------");
//    }
//
//    private List<String> performJoinQuery(String itemId, String tabName) {
//        SQLiteDatabase db = dbHelper.getReadableDatabase();
//
//        // SQL语句：查询用户表和订单表，根据用户ID关联
//        Cursor cursor = db.rawQuery("select box_one_lat,box_two_lat,box_three_lat,box_four_lat,box_five_lat,box_six_lat,box_seven_lat,box_eight_lat,box_nine_lat,box_ten_lat,box_eleven_lat,box_twelve_lat" +
//                " from " + tabName + " where item_id = ? ", new String[]{itemId});
//        System.out.println(cursor.getCount());
//        List<String> lis = new ArrayList<>();
//        // 遍历结果集
//        while (cursor.moveToNext()) {
//            String box_one_lat = cursor.getString(0);
//            String box_two_lat = cursor.getString(1);
//            String box_three_lat = cursor.getString(2);
//            String box_four_lat = cursor.getString(3);
//            String box_five_lat = cursor.getString(4);
//            String box_six_lat = cursor.getString(5);
//            String box_seven_lat = cursor.getString(6);
//            String box_eight_lat = cursor.getString(7);
//            String box_nine_lat = cursor.getString(8);
//            String box_ten_lat = cursor.getString(9);
//            String box_eleven_lat = cursor.getString(10);
//            String box_twelve_lat = cursor.getString(11);
//            lis.add(box_one_lat);
//            lis.add(box_two_lat);
//            lis.add(box_three_lat);
//            lis.add(box_four_lat);
//            lis.add(box_five_lat);
//            lis.add(box_six_lat);
//            lis.add(box_seven_lat);
//            lis.add(box_eight_lat);
//            lis.add(box_nine_lat);
//            lis.add(box_ten_lat);
//            lis.add(box_eleven_lat);
//            lis.add(box_twelve_lat);
//
//            // 处理查询结果
//            // ...
//        }
//
//        cursor.close();
//        db.close();
//        return lis;
//    }
//
//    private boolean socketListener() {
//        Timer timer1 = new Timer();
//        TimerTask task = new TimerTask() {
//            @Override
//            public void run() {
//                if (socketUtils.socketReconnection) {
//                    Log.e("socketReconnection", "-------------socketReconnection false-----------");
//                    socketUtils.socketReconnection = false;
//                    recv_float_bool = false;
//                    return;
//                }
//            }
//        };
//        timer1.schedule(task, 0, timeouts);
//        timer1.cancel();
//        if (recv_float_bool = false) {
//            return false;
//        }
//
//        //kSetTxWaveWithParam 3
//        if (anewSta) {
//            if (data != null) {
//
//                SocketMergeCallBackUtils.writeMsgByte(data, new Callback() {
//                    @Override
//                    public void onSuccess(byte[] data) {
//                        Log.i("SocketClient", "kSetTxWaveWithParam 3 Text sent successfully============= " + new String(data));
//                        String msg = new String(data);
//                        if (!msg.equals("")) {
//                            if (msg.contains(";")) {
//                                String[] lis1 = msg.split(";");
//                                if (lis1.length == 1) {
//                                    Boolean bl = getStatus(lis1[0].trim() + ";");
//                                    if (bl) {
//                                        myBool5 = sendkClearAllMuxBoxConnectOrder();
//                                        return;
//                                    }
//                                } else {
//                                    for (int i = 0; i < lis1.length; i++) {
//                                        Boolean bl = getStatus(lis1[i].trim() + ";");
//                                        if (bl) {
//                                            myBool5 = sendkClearAllMuxBoxConnectOrder();
//                                            return;
//                                        }
//                                    }
//                                }
//
//                            } else {
//                                Log.i("SocketClient", "kSetTxWaveWithParam 3 ----1 Text sent successfully============= " + Arrays.toString(data));
//                                stopMyThread();
//                                return;
//
//                            }
//                        }
//                    }
//
//                    @Override
//                    public void onFailure(String errorMessage) {
//                        Log.e("SocketClient", "kSetTxWaveWithParam 3 Failed to send text: " + errorMessage);
//                    }
//                });
//            }
//        }
//        return myBool5;
//    }
//
//    /**
//     * kClearAllMuxBoxConnect 15
//     */
//    private boolean sendkClearAllMuxBoxConnectOrder() {
//        Timer timer1 = new Timer();
//        TimerTask task = new TimerTask() {
//            @Override
//            public void run() {
//                if (socketUtils.socketReconnection) {
//                    Log.e("socketReconnection", "-------------socketReconnection false-----------");
//                    socketUtils.socketReconnection = false;
//                    recv_float_bool = false;
//                    return;
//                }
//            }
//        };
//        timer1.schedule(task, 0, timeouts);
//        timer1.cancel();
//        if (recv_float_bool = false) {
//            return false;
//        }
//        try {
//            Boolean clrearBuffer = socketUtils.clrearBufferNew();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        SocketMergeCallBackUtils.writeMsgByte(data2, new Callback() {
//            @Override
//            public void onSuccess(byte[] data) {
//                Log.i("SocketClient", "kClearAllMuxBoxConnect 15 Text sent successfully ============= " + new String(data));
//                String msg = new String(data);
//                if (!msg.equals("")) {
//                    if (msg.contains(";")) {
//                        String[] lis1 = msg.split(";");
//                        if (lis1.length == 1) {
//                            Boolean bl = getStatus(lis1[0].trim() + ";");
//                            if (bl) {
//                                myBool4 = sendkSetMuxBoxConnectOrder();
//                                return;
//                            } else {
//                                Boolean bool = true;
//                                while (bool) {
//                                    byte[] by = SocketMergeCallBackUtils.readDataHead();
//                                    if (by.length == 0) {
//                                        myThread.pauseThread();
//                                        Message msg1 = new Message();
//                                        msg1.what = MSG_RECEIVE_FAIL_DATA;
//                                        mHandler.sendMessage(msg1);
//                                        bool = false;
//                                        Log.e("kClearAllMuxBoxConnect 15", "======================== kClearAllMuxBoxConnect 15 false ================");
//                                        break;
//                                    }
//                                    String bystr = new String(by);
//                                    System.out.println("======================== Success15_00000 bad_param ================" + bystr);
//
//                                    if (!bystr.equals("")) {
//                                        if (bystr.equals("0,Success;")) {
//                                            System.out.println("======================== Success15_0 bad_param ================" + bystr);
//                                            myBool4 = sendkSetMuxBoxConnectOrder();
//                                            return;
//                                        } else if (bystr.equals("0,Timeout;")) {
//                                            sendkClearAllMuxBoxConnectOrder();
//                                            return;
//                                        } else {
//                                            getStatus(bystr);
//                                        }
//                                    }
//                                }
//                                if (!bool) {
//                                    myBool4 = false;
//                                    Log.e("kClearAllMuxBoxConnect 15", "======================== kClearAllMuxBoxConnect 15 false11111111111 ================");
//                                    return;
//                                }
//                            }
//                        } else {
//                            for (int i = 0; i < lis1.length; i++) {
//                                Boolean bl = getStatus(lis1[i].trim() + ";");
//                                if (bl) {
//                                    myBool4 = sendkSetMuxBoxConnectOrder();
//                                    return;
//                                } else {
//                                    if (lis1[i + 1].trim().equals("0,Success")) {
//                                        System.out.println("======================== Success15_1 bad_param ================" + lis1[i + 1].trim());
//                                        myBool4 = sendkSetMuxBoxConnectOrder();
//                                        return;
//                                    } else {
//                                        Boolean bool = true;
//                                        while (bool) {
//                                            byte[] by = SocketMergeCallBackUtils.readDataHead();
//                                            String bystr = new String(by);
//                                            if (!bystr.equals("")) {
//                                                if (bystr.equals("0,Success;")) {
//                                                    System.out.println("======================== Success15_2 bad_param ================" + bystr);
//                                                    myBool4 = sendkSetMuxBoxConnectOrder();
//                                                    return;
//                                                }
//                                            }
//                                        }
//                                    }
//
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(String errorMessage) {
//                Log.e("SocketClient", "kClearAllMuxBoxConnect 15 Failed to send text: " + errorMessage);
//            }
//        });
//        return myBool4;
//    }
//
//
//    /**
//     * kSetMuxBoxConnect 2
//     */
//    private boolean sendkSetMuxBoxConnectOrder() {
//        Timer timer1 = new Timer();
//        TimerTask task = new TimerTask() {
//            @Override
//            public void run() {
//                if (socketUtils.socketReconnection) {
//                    Log.e("socketReconnection", "-------------socketReconnection false-----------");
//                    socketUtils.socketReconnection = false;
//                    recv_float_bool = false;
//                    return;
//                }
//            }
//        };
//        timer1.schedule(task, 0, timeouts);
//        timer1.cancel();
//        if (recv_float_bool = false) {
//            return false;
//        }
//        try {
//            Boolean clrearBuffer = socketUtils.clrearBufferNew();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        SocketMergeCallBackUtils.writeMsgByte(data3, new Callback() {
//            @Override
//            public void onSuccess(byte[] data) {
//                Log.i("SocketClient", "kSetMuxBoxConnect 2 Text sent successfully ============= " + new String(data));
//                String msg = new String(data);
//                if (!msg.equals("")) {
//                    if (msg.contains(";")) {
//                        String[] lis1 = msg.split(";");
//                        if (lis1.length == 1) {
//                            Boolean bl = getStatus(lis1[0].trim() + ";");
//                            if (bl) {
//                                myBool3 = sendkPcResetAdcLogicOrder();
//                                return;
//                            } else {
//                                Boolean bool = true;
//                                while (bool) {
//                                    byte[] by = SocketMergeCallBackUtils.readDataHead();
//                                    if (by.length == 0) {
//                                        return;
//                                    }
//                                    String bystr = new String(by);
//                                    Boolean bl1 = getStatus(bystr);
//                                    if (bl1) {
//                                        myBool3 = sendkPcResetAdcLogicOrder();
//                                        return;
//                                    }
//                                }
//                                return;
//                            }
//                        } else {
//                            for (int i = 0; i < lis1.length; i++) {
//                                Boolean bl = getStatus(lis1[i].trim() + ";");
//                                if (bl) {
//                                    myBool3 = sendkPcResetAdcLogicOrder();
//                                    return;
//                                } else {
//                                    Boolean bool = true;
//                                    while (bool) {
//                                        byte[] by = SocketMergeCallBackUtils.readDataHead();
//                                        String bystr = new String(by);
//                                        if (!bystr.equals("")) {
//                                            if (bystr.equals("0,Success;")) {
//                                                System.out.println("======================== Success0 bad_param ================" + bystr);
//                                                myBool3 = sendkPcResetAdcLogicOrder();
//                                                return;
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(String errorMessage) {
//                Log.e("SocketClient", "kSetMuxBoxConnect 2 Failed to send text: " + errorMessage);
//            }
//        });
//        return myBool3;
//    }
//
//    /**
//     * kPcResetAdcLogic 23
//     */
//    private boolean sendkPcResetAdcLogicOrder() {
//        Timer timer1 = new Timer();
//        TimerTask task = new TimerTask() {
//            @Override
//            public void run() {
//                if (socketUtils.socketReconnection) {
//                    Log.e("socketReconnection", "-------------socketReconnection false-----------");
//                    socketUtils.socketReconnection = false;
//                    recv_float_bool = false;
//                    return;
//                }
//            }
//        };
//        timer1.schedule(task, 0, timeouts);
//        timer1.cancel();
//        if (recv_float_bool = false) {
//            return false;
//        }
//        try {
//            Boolean clrearBuffer = socketUtils.clrearBufferNew();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        String data = "23,r;";
//        SocketMergeCallBackUtils.writeMsgByte(data.getBytes(), new Callback() {
//            @Override
//            public void onSuccess(byte[] data) {
//                Log.i("SocketClient", "kPcResetAdcLogic 23 Text sent successfully ============= " + new String(data));
//                String msg = new String(data);
//                if (!msg.equals("")) {
//                    if (msg.contains(";")) {
//                        String[] lis1 = msg.split(";");
//                        if (lis1.length == 1) {
//                            Boolean bl = getStatus(lis1[0].trim() + ";");
//                            if (bl) {
//                                myBool2 = sendkSartAdcSampleOnceOrder();
//                                return;
//                            } else {
//                                Boolean bool = true;
//                                while (bool) {
//                                    byte[] by = SocketMergeCallBackUtils.readDataHead();
//                                    String bystr = new String(by);
//                                    Boolean bl1 = getStatus(bystr);
//                                    if (bl1) {
//                                        myBool2 = sendkSartAdcSampleOnceOrder();
//                                        return;
//                                    }
//                                }
//                            }
//                        } else {
//                            for (int i = 0; i < lis1.length; i++) {
//                                Boolean bl = getStatus(lis1[i].trim() + ";");
//                                if (bl) {
//                                    myBool2 = sendkSartAdcSampleOnceOrder();
//                                    return;
//                                } else {
//                                    Boolean bool = true;
//                                    while (bool) {
//                                        byte[] by = SocketMergeCallBackUtils.readDataHead();
//                                        String bystr = new String(by);
//                                        if (!bystr.equals("")) {
//                                            if (bystr.equals("0,Success;")) {
//                                                System.out.println("======================== Success0 bad_param ================" + bystr);
//                                                myBool2 = sendkSartAdcSampleOnceOrder();
//                                                return;
//                                            }
//                                        }
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(String errorMessage) {
//                Log.e("SocketClient", "kPcResetAdcLogic 23 Failed to send text: " + errorMessage);
//            }
//        });
//        return myBool2;
//    }
//
//    /**
//     * kSartAdcSampleOnce 4
//     */
//    private boolean sendkSartAdcSampleOnceOrder() {
//        Timer timer1 = new Timer();
//        TimerTask task = new TimerTask() {
//            @Override
//            public void run() {
//                if (socketUtils.socketReconnection) {
//                    Log.e("socketReconnection", "-------------socketReconnection false-----------");
//                    socketUtils.socketReconnection = false;
//                    recv_float_bool = false;
//                    return;
//                }
//            }
//        };
//        timer1.schedule(task, 0, timeouts);
//        timer1.cancel();
//        if (recv_float_bool = false) {
//            return false;
//        }
//        try {
//            Boolean clrearBuffer = socketUtils.clrearBufferNew();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        String data = "4,start;";
//        SocketMergeCallBackUtils.writeMsgByte(data.getBytes(), new Callback() {
//            @Override
//            public void onSuccess(byte[] data) {
//                Log.i("SocketClient", "kSartAdcSampleOnce 4 Text sent successfully ============= " + new String(data));
//                myBool = true;
//
//                String msg = new String(data);
//                //msg = "0,Success;";
//                if (!msg.equals("")) {
//                    if (msg.contains(";")) {
//                        String[] lis1 = msg.split(";");
//                        if (lis1.length > 0) {
//                            if (lis1[lis1.length - 1].equals("0,Success;")) {
//                                Boolean bool = true;
//                                ArrayList<Byte> bylist = new ArrayList<Byte>();
//                                while (bool) {
//                                    byte buf = SocketMergeCallBackUtils.read();
//                                    if (buf != 59) {
//                                        bylist.add(buf);
//                                    } else {
//                                        bylist.add(buf);
//                                        byte[] bytes = ByteUtil.convertByteListToArray(bylist);
//                                        myBool = ReceiveDataForAnalyze(bytes);
//                                        bool = true;
//                                    }
//                                }
//
//                            } else if (lis1[lis1.length - 1].equals("0,wait;")) {
//                                Boolean bool = true;
//                                while (bool) {
//                                    byte[] by = SocketMergeCallBackUtils.readDataHead();
//                                    String bystr = new String(by);
//                                    Boolean bl1 = getStatus(bystr);
//                                    if (bl1) {
//                                        byte[] bytes = ArrayUtil.subByte(by, 8, by.length);
//                                        myBool = ReceiveDataForAnalyze(bytes);
//                                        return;
//                                    }
//                                }
//                            } else if (lis1[lis1.length - 1].equals("0,alarm")) {
//                                Boolean bl1 = getStatus(msg);
//
//                                stopMyThread();
//                                myThread.pauseThread();
//                            } else {
//                                if (new String(data).equals("0,wait;0,Success;")) {
//                                    System.out.println(" 4 ------------------ data == 0,wait;0,Success;");
//                                    Boolean bool = true;
//                                    ArrayList<Byte> bylist = new ArrayList<Byte>();
//                                    while (bool) {
//                                        byte buf = SocketMergeCallBackUtils.read();
//                                        if (buf != 59) {
//                                            bylist.add(buf);
//                                        } else {
//                                            bylist.add(buf);
//                                            byte[] bytes = ByteUtil.convertByteListToArray(bylist);
//                                            myBool = ReceiveDataForAnalyze(bytes);
//                                            bool = false;
//                                        }
//                                    }
//                                } else {
//                                    System.out.println(" 4 ------------------ data == " + Arrays.toString(data));
//                                    if (new String(data).equals("0,Success;")) {
//                                        Boolean bool = true;
//                                        ArrayList<Byte> bylist = new ArrayList<Byte>();
//                                        while (bool) {
//                                            byte buf = SocketMergeCallBackUtils.read();
//                                            if (buf != 59) {
//                                                bylist.add(buf);
//                                            } else {
//                                                bylist.add(buf);
//                                                byte[] bytes = ByteUtil.convertByteListToArray(bylist);
//                                                myBool = ReceiveDataForAnalyze(bytes);
//                                                bool = false;
//                                            }
//                                        }
//                                    } else {
//                                        byte[] bytes = ArrayUtil.subByte(data, 10, 10);
//                                        if (bytes[bytes.length - 1] != 59) {
//                                            Boolean bool = true;
//                                            byte[] bylist = new byte[1];
//                                            while (bool) {
//                                                byte buf = SocketMergeCallBackUtils.read();
//                                                bylist[0] = buf;
//                                                byte[] bytes1 = (byte[]) ArrayUtils.toPrimitive(bylist);
//                                                byte[] byAll = ArrayUtil.byteMerger(data, bytes1);
//                                                System.out.println(" 4 ------------------ alldata == " + Arrays.toString(byAll));
//                                                byte[] bytes2 = ArrayUtil.subByte(byAll, 10, 11);
//                                                myBool = ReceiveDataForAnalyze(bytes2);
//                                                bool = false;
//                                                break;
//                                            }
//                                        } else {
//                                            myBool = ReceiveDataForAnalyze(bytes);
//                                        }
//                                    }
//
//                                }
//
//                            }
//                        }
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(String errorMessage) {
//                Log.e("SocketClient", "kSartAdcSampleOnce 4 Failed to send text: " + errorMessage);
//            }
//        });
//        return myBool;
//    }
//
//
//    /**
//     * 解析报文头信息及数据 10,1024,8....
//     */
//    public boolean ReceiveDataForAnalyze(byte[] data) {
//        Boolean bool1 = false;
//        List<Byte> datelist = new ArrayList<Byte>();
//        try {
//            byte buf = SocketMergeCallBackUtils.read();
//            System.out.println("=========== ReceiveDataForAnalyze buf ==========" + buf);
//            receiveDataAll = new String(data, "iso8859-1");
//            // test_cout += 1;
//            Log.i("receiveDataAll", "============= 解析报文头信息及数据 receiveDataAll================" + receiveDataAll + "  test_cout= " + test_cout);
//
////            if(test_cout == 2){
////                Log.i("receiveDataAll", "============= 2=4=6 ==============");
////                Boolean clrearBuffer0 = socketUtils.clrearBuffer();
////                return false;
////            }
//
//            if (!receiveDataAll.contains("10,")) {
//                Log.i("receiveDataAll", "=============44444444444444444444444================");
//                Boolean clrearBuffer = socketUtils.clrearBuffer();
//                return false;
//            }
//            indexsum = 0;
//            cmd_index_len = DataParseUtil.getDataForHeaderIndex(receiveDataAll);
//            packet_indx = Integer.valueOf(DataParseUtil.initPython(cmd_index_len.split(",")[1]));
//            packet_lens = Integer.valueOf(DataParseUtil.initPython(cmd_index_len.split(",")[2]));
//            toatalByte = packet_lens / 3 * 21;
//            System.out.println("--------ReceiveDataForAnalyze  packet_indx==" + packet_indx + " = " + packet_lens);
//            indexsum = packet_lens / 3 + 1;
//            packet_lens_old = packet_lens;
//            packet_indx_old = packet_indx;
//            SocketMergeCallBackUtils.packet_indx = packet_indx;
//            DataParseUtil.setPageLens(packet_lens);
//            receiveDataAll = "";
//            bool1 = true;
//
//        } catch (JSONException e) {
//            // throw new RuntimeException(e);
//            myThread.pauseThread();
//            String msg1 = "采集数据失败！";
//            Message msg = new Message();
//            msg.what = MSG_RECEIVE_TOAST_DATA;
//            msg.obj = msg1;
//            mHandler.sendMessage(msg);
//        } catch (InterruptedException e) {
//            //throw new RuntimeException(e);
//            myThread.pauseThread();
//            String msg1 = "采集数据失败！";
//            Message msg = new Message();
//            msg.what = MSG_RECEIVE_TOAST_DATA;
//            msg.obj = msg1;
//            mHandler.sendMessage(msg);
//        } catch (IOException e) {
//            //throw new RuntimeException(e);
//            myThread.pauseThread();
//            String msg1 = "采集数据失败！";
//            Message msg = new Message();
//            msg.what = MSG_RECEIVE_TOAST_DATA;
//            msg.obj = msg1;
//            mHandler.sendMessage(msg);
//        } finally {
//        }
//        return bool1;
//    }
//
//    /**
//     * 解析报文头信息及数据 10,1024,8....
//     */
//    public boolean ReceiveDataForAnalyze1(byte[] data) {
//        Boolean bool1 = false;
//        List<Byte> datelist = new ArrayList<Byte>();
//        try {
//            byte buf = SocketMergeCallBackUtils.read();
//            System.out.println("=========== ReceiveDataForAnalyze buf ==========" + buf);
//            receiveDataAll = new String(data, "iso8859-1");
//            Log.i("receiveDataAll", "=============receiveDataAll================" + receiveDataAll);
////            test_cout += 1;
////            if(test_cout == 2){
////                Log.i("receiveDataAll", "============= 3333333333333333333333 ==============");
////                Boolean clrearBuffer = socketUtils.clrearBuffer();
////                stopMyThread();
////                return false;
////            }
//
//            if (!receiveDataAll.contains("10,")) {
//                Log.i("receiveDataAll", "=============555555555555555555555555================");
//                stopMyThread();
//                return false;
//            }
//            cmd_index_len = DataParseUtil.getDataForHeaderIndex(receiveDataAll);
//            packet_indx = Integer.valueOf(DataParseUtil.initPython(cmd_index_len.split(",")[1]));
//            packet_lens = Integer.valueOf(DataParseUtil.initPython(cmd_index_len.split(",")[2]));
//            System.out.println("--------ReceiveDataForAnalyze  packet_indx==" + packet_indx + " = " + packet_lens);
//            packet_lens_old = packet_lens;
//            packet_indx_old = packet_indx;
//            SocketMergeCallBackUtils.packet_indx = packet_indx;
//            DataParseUtil.setPageLens(packet_lens);
//            receiveDataAll = "";
//            bool1 = true;
//
//        } catch (JSONException e) {
//            // throw new RuntimeException(e);
//            myThread.pauseThread();
//            String msg1 = "采集数据失败！";
//            Message msg = new Message();
//            msg.what = MSG_RECEIVE_TOAST_DATA;
//            msg.obj = msg1;
//            mHandler.sendMessage(msg);
//        } catch (InterruptedException e) {
//            //throw new RuntimeException(e);
//            myThread.pauseThread();
//            String msg1 = "采集数据失败！";
//            Message msg = new Message();
//            msg.what = MSG_RECEIVE_TOAST_DATA;
//            msg.obj = msg1;
//            mHandler.sendMessage(msg);
//        } catch (IOException e) {
//            //throw new RuntimeException(e);
//            myThread.pauseThread();
//            String msg1 = "采集数据失败！";
//            Message msg = new Message();
//            msg.what = MSG_RECEIVE_TOAST_DATA;
//            msg.obj = msg1;
//            mHandler.sendMessage(msg);
//        } finally {
//        }
//        return bool1;
//    }
//
//    /**
//     * 查询告警，并写入数据库
//     * 1.发送18，get;读取success后截取数据，
//     * 2.调用getAlarm13方法 发送13,update;命令
//     */
//    private void getAlarm18() {
//        String data = "18,get;";
//        SocketMergeCallBackUtils.writeMsg18(data, new Callback() {
//            @Override
//            public void onSuccess(byte[] data) {
//                Log.i("SocketClient", "Alarm 18 Text sent successfully ============= " + new String(data));
//                String msg = new String(data);
//                if (!msg.equals("")) {
//                    String msglis_18 = ByteUtil.byteTransformAscil(data);
//                    //System.out.println("  msglis_18 ===================="+ msglis_18);
//                    deviceId = msglis_18.split(",")[1];//固件版本
//                    if (!deviceId.equals("")) {
//                        //读取success后截取数据，再发送13命令
//                        getAlarm13();
//                    }
//                }
//            }
//
//            @Override
//            public void onFailure(String errorMessage) {
//                Log.e("SocketClient", "Alarm 18 Failed to send text: " + errorMessage);
//            }
//        });
//    }
//
//    private void getAlarm13() {
//        String data = "13,update;";
//        SocketMergeCallBackUtils.writeMsg14(data, new Callback() {
//            @Override
//            public void onSuccess(byte[] data) throws UnsupportedEncodingException {
//                Log.i("SocketClient", "Alarm 13 Text sent successfully ============= " + Arrays.toString(data));
//                String msg = Arrays.toString(data);
//                for (byte b : data) {
//                    queueAlarm.enQueue(b);
//                }
//                try {
//                    for (int i = 0; i < 3; i++) {
//                        queueAlarm.deQueue();
//                    }
//                    Double batt_vol = Double.valueOf(receive_one_field_alarm());//电源
//                    System.out.println("  电源电压 ====================" + batt_vol);
//                    String tx_high_vol = receive_one_field_alarm();//高压
//                    String temperature1 = receive_one_field_alarm();//温度
//                    String humidity1 = receive_one_field_alarm();//湿度
//                    String alarm = receive_one_field_alarm();//告警
//                    String outEle = receive_one_field_alarm();//外部电源
//                    if (!msg.equals("")) {
//
//                        System.out.println("  alarm ====================" + alarm);
//                        switch (alarm) {
//                            case "2":
//                                alarmVal = "RX接受的电压超最大量程范围";
//                                break;
//                            case "5":
//                                alarmVal = "电池电压低";
//                                break;
//                            case "6":
//                                alarmVal = "高压未达到预设值";
//                                break;
//                            case "7":
//                                alarmVal = "用户主动紧急停止 或 TX电流超范围";
//                                break;
//                        }
//                        //System.out.println("  alarm ====================" + alarm);
//                        if (!alarm.equals("")) {
//                            Items items = findSelectItem();
//                            String itemsId = items.getId().toString();
//                            alarmService = new AlarmService();
//                            Alarm alarm1 = new Alarm();
//                            alarm1.setAlarmMsg(send_piont + receive_piont + ":" + alarmVal);
//                            alarm1.setSn(deviceId);
//                            alarm1.setItemId(itemsId);
//                            alarm1.setStatus(0);
//                            SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//                            Date date = new Date(System.currentTimeMillis());
//                            alarm1.setCreateTime(sim.format(date));
//                            alarm1.setUpdateTime(sim.format(date));
//                            alarmService.save(alarm1);
//                            queueAlarm.clear();
//                            stopMyThread();
//                            myThread.pauseThread();
//                            socketUtils.isReConnect = false;
//                            alarmSta = true;
//                            // socketUtils.releaseSocket();
//
//                        }
//
//                    }
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
//
//
//            }
//
//            @Override
//            public void onFailure(String errorMessage) {
//                Log.e("SocketClient", "kPcResetAdcLogic 23 Failed to send text: " + errorMessage);
//            }
//        });
//    }
//
//    public synchronized String receive_one_field_alarm() throws InterruptedException, UnsupportedEncodingException {
//        Boolean escaped = false;
//        Boolean command_sep_found = false;
//        ArrayList<Byte> one_field = new ArrayList<Byte>();
//        Boolean bl = true;
//        String msgbt = "";
//        while (bl) {
//
//            byte tmp = (byte) queueAlarm.deQueue();
//            if (escaped) {
//                if (tmp == 44 || tmp == 59 || tmp == 47) {
//                    one_field.add(tmp);
//                    escaped = false;
//                } else {
//                    one_field.add(tmp);
//                    escaped = false;
//                }
//            } else {
//                if (tmp == 47) {
//                    //遇到 / 就escaped = True 继续循环
//                    escaped = true;
//                } else if (tmp == 44) {
//                    break;
//                } else if (tmp == 59) {
//                    command_sep_found = true;
//                    break;
//                } else {
//                    one_field.add(tmp);
//                }
//            }
//
//        }
//        if (one_field.size() > 0) {
//            msgbt = socketUtils.recv_float_alarm(one_field);
//        }
//
//        return msgbt;
//    }
//
//    private boolean getStatus(String message) {
//        Boolean stabool = false;
//        if (message.contains("0,Success;") && !message.equals("")) {
//            System.out.println("======================== Success bad_param ================" + message);
//            stabool = true;
//        } else if (message.contains("0,wait;")) {
//            System.out.println("======================== wait bad_param ================" + message);
//            stabool = false;
//        } else if (message.contains("0,Timeout;")) {
//            System.out.println("======================== bad_param ================" + message);
//            System.out.println(" kSetMuxBoxConnect switch box connect error ");
//            stabool = false;
//            String msg1 = "开关盒子连接出错！";
//            stopMyThread();
//            Message msg = new Message();
//            msg.what = MSG_RECEIVE_TOAST_DATA;
//            msg.obj = msg1;
//            mHandler.sendMessage(msg);
//        } else if (message.equals("0,Bad_Param;") || message.equals("0,BadParam;")) {
//            System.out.println("======================== bad_param ================" + message);
//            stabool = false;
//            String msg1 = "ABMN配置错误！";
//            Message msg = new Message();
//            msg.what = MSG_RECEIVE_TOAST_DATA;
//            msg.obj = msg1;
//            mHandler.sendMessage(msg);
//        } else if (message.equals("0,alarm;")) {
//            System.out.println("========================alarm bad_param ================" + message);
//            getAlarm18();
//            stabool = false;
//            String msg1 = "设备告警！";
//            Message msg = new Message();
//            msg.what = MSG_RECEIVE_TOAST_DATA;
//            msg.obj = msg1;
//            mHandler.sendMessage(msg);
//        } else if (message.equals("None")) {
//            System.out.println(" usb/wifi connect error ");
//            stabool = false;
//        } else if (message.contains("kErrorAlarm")) {//告警写入
//            System.out.println(" kErrorAlarm================= " + message);
//            Alarm alarm = new Alarm(itemsId);
//            alarm.setAlarmMsg(message);
//            alarmService.save(alarm);
//            stabool = false;
//        } else if (message.equals("null")) {
//            if (startCount == 1) {
//                stabool = false;
//                String msg1 = "采集数据失败！";
//                Message msg = new Message();
//                msg.what = MSG_RECEIVE_TOAST_DATA;
//                msg.obj = msg1;
//                mHandler.sendMessage(msg);
//            }
//        }
//        return stabool;
//    }
//
//
//    public void getTask() {
//        //SocketMergeCallBackUtils.success_count = 6;
//        byte[] data5 = pyobj1.callAttr("onKReSync", SocketMergeCallBackUtils.packet_indx).toJava(byte[].class);
//        SocketMergeCallBackUtils.writeMsgByte(data5, new Callback() {
//            @Override
//            public void onSuccess(byte[] data) {
//                Log.i("SocketClient  17", "Text sent successfully ============= " + new String(data));
//            }
//
//            @Override
//            public void onFailure(String errorMessage) {
//                Log.e("SocketClient", "Failed to send text: " + errorMessage);
//            }
//        });
//        System.out.println(" 超时重复开始= " + DateUtils.parseYmdHmsDate());
//    }
//
//    private void getTexts() throws InterruptedException {
//        test_cout = 0;
////        if (send_voltage_val.getText().length() == 0) {
////            Toast.makeText(myContext, "电压不能为空！", Toast.LENGTH_SHORT).show();
////            return;
////        }
////        if (send_repeat_val.getText().length() == 0) {
////            Toast.makeText(myContext, "重复次数不能为空！", Toast.LENGTH_SHORT).show();
////            return;
////        }
//
////        if (send_duration_val.getText().length() ==0){
////            Toast.makeText(myContext, "发射时长不能为空！", Toast.LENGTH_SHORT).show();
////            return;
////        }
////        if (clear_all_mux_box_connect_val.getText().length() == 0) {
////            Toast.makeText(myContext, "重置电极不能为空！", Toast.LENGTH_SHORT).show();
////            return;
////        }
//        startCount = 1;
//        if (socketUtils.socket == null) {
//            socketUtils = SocketMergeCallBackUtils.getInstance(myContext);
//            Thread.sleep(1000);
//
//        } else {
//            System.out.println("------------SendReceive_SocketMergeCallBackUtils.resumeThread()------------");
//            //socketUtils.startListening();
//
//            //SocketMergeCallBackUtils.resumeThread();
//        }
//        myThread = new MyThread();
//        if (queue == null) {
//            queue = new MyQueue();
//        }
//        if (inclickGatherCount > 0) {
//            Thread.sleep(1000);
//        }
//        //SocketMergeCallBackUtils.success_count = 1;
////        myThread = new MyThread();
//
//        packet_indx1 = Integer.parseInt(String.valueOf(send_repeat_val.getSelectedItemPosition()));
//        packet_indx = packet_indx1;
//        Sends sends = new Sends();
//        sends.setVoltage(String.valueOf(send_voltage_val.getSelectedItemPosition()));
//        sends.setType(0);
//        sends.setStatus(0);
//        sends.setRepeatNum(String.valueOf(send_repeat_val.getSelectedItemPosition()));
//        sends.setSendFrequency(String.valueOf(send_frequency_val.getSelectedItemPosition()));
//        sends.setFilterFrequency(String.valueOf(send_filter_frequency_val.getSelectedItemPosition()));
//        //sf = String.valueOf(send_frequency_val.getSelectedItemPosition() + 1);
//        sf = freqData[send_frequency_val.getSelectedItemPosition()];
//        srepeat = repeatData[send_repeat_val.getSelectedItemPosition()];
//        svaltage = valtageData[send_voltage_val.getSelectedItemPosition()];
//
//        //sends.setSendDuration(String.valueOf(send_duration_val.getText()));
//
//        //Items items = findSelectItem();
//        //itemsId = items.getId().toString();
//        sends.setItemId(Integer.valueOf(itemsId));
//        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//        Date date = new Date(System.currentTimeMillis());
//        sends.setCreateTime(sim.format(date));
//        sends.setUpdateTime(sim.format(date));
//        simpleUUID = IdUtil.simpleUUID();
//        fileName = FileDownUtil.getFileName(simpleUUID);
//        sends.setUid(simpleUUID);
//        sendsService = new SendsService();
//        receiveVolEleService = new ReceiveVolEleService();
//        Arrange arrange1 = new Arrange();
//        arrange1.setItemId(Integer.valueOf(itemsId));
//        List<Arrange> arrangeLis = arrangeService.getArrange(arrange1);
//        Integer ns = 0;
//
//        if (arrangeLis.size() == 0) {
//            Toast.makeText(myContext, "请先添加排列设计！", Toast.LENGTH_SHORT).show();
//            return;
//        } else {
//            ns = arrangeLis.get(0).getDeviceTypeLen();
//            dtype = arrangeLis.get(0).getDtype();
//            dtypelen = arrangeLis.get(0).getDeviceTypeLen();
//            shape = arrangeLis.get(0).getShape();
//            abmn = arrangeLis.get(0).getDeviceTypeVal();
//            devtype = arrangeLis.get(0).getDeviceType();
//            permutationMode = modeData[devtype];//添加采集模式
//            //dtypelen0 = dtypelen;
//        }
//
//
//        int countItem = findItemCount();
//
//        if (countItem > 0) {
//            boolean bl = sendsService.save(sends);
//            if (bl) {
//                initData();
//                Toast.makeText(myContext, "保存成功！", Toast.LENGTH_SHORT).show();
//                SharedPreferences.Editor editor = mSharedPreferences.edit();
//                editor.putInt("header_count", 0);
//                editor.remove("header");// 初始化清空header
//                showPopupWindow();//pop弹框
//                if (inclickGatherCount == 0) {
//                    Log.e("myThread.getState()", "myThread.getState()=========" + myThread.getState());
//                    if (myThread.getState() == Thread.State.TERMINATED) {
//                        myThread = new MyThread();
//                        myThread.start();
//                    } else if (myThread.getState() == Thread.State.NEW) {
//                        myThread.start();
//                    }
//
//                } else {
//                    inclickGatherCount = 0;
//                    myThread.resumeThread();
//                    returnSta = true;
////                    SocketMergeCallBackUtils.success_count = 0;
//                    String data = "22,M;";
//                    //SocketMergeCallBackUtils.writeMsgByte(data.getBytes());
//                    Thread.sleep(1000);
//                    SocketMergeCallBackUtils.success_count = 0;
//                    SocketMergeCallBackUtils.writeMsgByte(data.getBytes(), new Callback() {
//                        @Override
//                        public void onSuccess(byte[] data) {
//                            Log.i("SocketClient", "Text sent successfully ============= " + new String(data));
//                            String msg = new String(data);
//                            if (!msg.equals("")) {
//                                getStatus(msg);
//                            }
//                        }
//
//                        @Override
//                        public void onFailure(String errorMessage) {
//                            Log.e("SocketClient", "Failed to send text: " + errorMessage);
//                            SocketMergeCallBackUtils.writeMsgByte(data.getBytes(), new Callback() {
//                                @Override
//                                public void onSuccess(byte[] data) {
//                                    Log.i("SocketClient time out", "Text sent successfully ============= " + new String(data));
//                                    String msg = new String(data);
//                                    if (!msg.equals("")) {
//                                        getStatus(msg);
//                                    }
//                                }
//
//                                @Override
//                                public void onFailure(String errorMessage) {
//                                    Log.e("SocketClient", "Failed to send text: " + errorMessage);
//                                }
//                            });
//                        }
//                    });
//                }
//
//            }
//
//        } else {
//            Toast.makeText(myContext, "请先创建项目！", Toast.LENGTH_SHORT).show();
//
//        }
//
//    }
//
//    class MyThread extends Thread {
//        public final Object lock = new Object();
//        public boolean threadExit;
//
//
//        public MyThread() {
//            threadExit = false;
//        }
//
//        /**
//         * 调用这个方法实现暂停线程
//         */
//        public void pauseThread() {
//            threadExit = true;
//        }
//
//        /**
//         * 调用这个方法实现恢复线程的运行
//         */
//        public void resumeThread() {
//            threadExit = false;
//            synchronized (lock) {
//                lock.notifyAll();
//            }
//        }
//
//        public void threadExit() {
//            threadExit = true;
//        }
//
//        /**
//         * 注意：这个方法只能在run方法里调用，不然会阻塞主线程，导致页面无响应
//         */
//        public void onPause() {
//            synchronized (lock) {
//                try {
//                    lock.wait();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//
//        @Override
//        public void run() {
//            System.out.println("---------------dtypelen---" + dtypelen);
//            System.out.println("---------------threadExit---" + threadExit);
//
//            while (!Thread.currentThread().isInterrupted()) {
//                while (!threadExit) {
//                    //Log.i(TAG, "-------------------------run: socket " + socketUtils.socket);
//                    if (null != socketUtils.socket) {
//
//                        msg_sueecss_count = 1;
//                        //returnSta = false;
//                        String abmnStr = "";
//                        if (inclickGatherCount == 0) {
//                            System.out.println("---------------dtypelen0---" + 0);
//                            abmnStr = pyobj1.callAttr("subABMN", abmn, dtype, shape, 0).toJava(String.class);
//
//                        } else {
//
//                            //System.out.println("---------------dtypelen1---"+dtypelen1);
//                            //int dtypelen2 = dtypelen - dtypelen1;
//                            System.out.println("---------------dtypelen0---" + dtypelen0);
//                            if (dtypelen0 == dtypelen) {
//                                //将未压缩的cvs文件 移动到文件中 一并压缩导出
//
//                                send_pop_status.setText("采集结束");
//                                pauseThread();
//                                new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        //socketUtils.releaseSocket();//接收结束 关闭socket避免 超时操作
//                                        Message msg = new Message();
//                                        msg.what = MSG_RECEIVE_OVER_DATA;
//                                        mHandler.sendMessage(msg);
//
//                                        String destinationPath = DOWN_NAME + fileName.replace(".cvs", "") + "/" + saveCvsFileName;
//                                        String destinationPathNoDownName = fileName.replace(".cvs", "") + "/" + saveCvsFileName;
//                                        String fileNameNew = fileName.replace(".cvs", "") + "/" + saveCvsFileName;
//                                        Boolean boo = FileDownUtil.moveFile(DOWN_NAME + saveCvsFileName, destinationPath, myContext);//移动csv文件
//                                        try {
//                                            Thread.sleep(2000);
//                                            //将剩下的未压缩csv文件压缩、删除
//                                            FileDownUtil.GZIPFile(fileName,destinationPathNoDownName);
//
//                                        } catch (InterruptedException e) {
//                                            throw new RuntimeException(e);
//                                        }
////                                        Boolean boorMS = FileDownUtil.moveFile(DOWN_NAME + "RMS_" + saveCvsFileName, DOWN_NAME + fileName.replace(".cvs", "") + "/" + "RMS_" + saveCvsFileName, myContext);
////                                        //FileDownUtil.deleteFile(DOWN_NAME + saveCvsFileName);
////                                        Log.e("cvs移动到文件", "cvs移动到文件====================" + String.valueOf(boo));
//
//                                    }
//                                }).start();
//                                dtypelen = 0;
//                                //returnSta = false;
//                                return;
//                            } else if (dtypelen0 > dtypelen) {
//                                return;
//                            }
//                            System.out.println("---------------subABMN---");
//                            abmnStr = pyobj1.callAttr("subABMN", abmn, dtype, shape, dtypelen0).toJava(String.class);
//                            if (dtypelen0 % boxId == 0) {
//                                boxInx += 1;
//                            }
//                        }
//
//
//                        if (abmnStr.length() > 0) {
//                            if(devtype==0 || devtype ==1){
//                                abmnlis = abmnStr.split(",");
//                            }else {
//                                String[] abmnliswn = abmnStr.split(",");
//                                // 临时变量存储元素
//                                String tempA = abmnliswn[0];
//                                String tempB = abmnliswn[3];
//                                String tempM = abmnliswn[1];
//                                String tempN = abmnliswn[2];
//                                abmnlis = new String[4];
//                                abmnlis[0] = tempA;
//                                abmnlis[1] = tempB;
//                                abmnlis[2] = tempM;
//                                abmnlis[3] = tempN;
//                            }
//
//                        }
//
//                        //kSetTxWaveWithParam 3
//                        System.out.println("---------------onSendParamToMcu---");
//                        data = pyobj1.callAttr("onSendParamToMcu", 2, send_frequency_val.getSelectedItemPosition() + 1, srepeat, svaltage).toJava(byte[].class);
//
//                        //kClearAllMuxBoxConnect 15
//                        Log.e("boxlis", "==========boxlis===========" + Arrays.toString(boxlis));
//                        if (boxlis.length > 0) {
//                            data2 = pyobj1.callAttr("clear_mux", boxlis[0], boxlis[1], boxlis[2], boxlis[3], boxlis[4],
//                                    boxlis[5], boxlis[6], boxlis[7], boxlis[8], boxlis[9]).toJava(byte[].class);
//                        }
//
//                        //kSetMuxBoxConnect 2
//                        String box = SwitchBoxUtil.boxIdToSpilt(alis, Integer.parseInt(abmnlis[0]));
//                        String box2 = SwitchBoxUtil.boxIdToSpilt(alis, Integer.parseInt(abmnlis[1]));
//                        String box3 = SwitchBoxUtil.boxIdToSpilt(alis, Integer.parseInt(abmnlis[2]));
//                        String box4 = SwitchBoxUtil.boxIdToSpilt(alis, Integer.parseInt(abmnlis[3]));
//                        Arrange arrange = new Arrange();
//                        arrange.setItemId(Integer.valueOf(itemsId));
//                        List<Arrange> arrangeLis = arrangeService.getArrange(arrange);
//                        Integer model = 0;
//                        if (arrangeLis.size() > 0) {
//                            model = arrangeLis.get(0).getDeviceType();
//                        }
//
//                        data3 = pyobj1.callAttr("update_poles_connect", box, box2,
//                                box3, box4, model).toJava(byte[].class);
//                        send_piont = "A" + box.replace(",", ":") + "; " + "B" + box2.replace(",", ":");
//                        receive_piont = "M" + box3.replace(",", ":") + "; " + "N" + box4.replace(",", ":");
//                        receive_duration_pop_val.setText(send_piont + "; " + receive_piont);
//                        loding_count = 1;
//
//                        try {
//                            if (!startGater) {
//                                //Thread.sleep(1);
//                                //pauseThread();
//                                if (socketUtils.socketReconnection) {
//                                    socketUtils.socketReconnection = false;
//                                    recv_float_bool = false;
//                                } else {
//                                    System.out.println("---------------socketListener00000000---");
//                                    Boolean socketListenerBoo = socketListener();
//                                    System.out.println("---------------socketListener---  " + socketListenerBoo);
//                                    if (socketListenerBoo) {
//                                        myBool = false;
//                                        myBool2 = false;
//                                        myBool3 = false;
//                                        myBool4 = false;
//                                        myBool5 = false;
//                                        recv_float_bool = true;
//                                        //receive_data();
//                                        returnSta = recv_float_array_with_indx(abmnlis);
//
//                                        Log.e("returnSta", "----------returnSta=-------------" + returnSta);
//                                        if (returnSta) {
//                                            dtypelen0 += 1;
//                                            startCount = 0;
//                                            inclickGatherCount += 1;
//                                            abmn_indx += 1;
//                                            receiveDataAll = "";
//                                            packet_indx = 0;
//                                            packet_lens = 0;
//                                            packet_lens_old = 0;
//                                            clearLis();
//                                            // resumeThread();
//                                        } else {
//                                            socketUtils.socketReconnection = false;
//                                            rec_count = 0;
//                                            rx_voltage_data1 = new StringBuffer();
//                                            tx_current_data1 = new StringBuffer();
//                                            rx_voltage_data_all1 = new StringBuffer();
//                                            //VIRO_part.clear();
//                                            //VIRO.clear();
//                                            recv_float_bool = true;
//                                            returnSta = true;
//                                            receive_one_field_sta = true;
//                                            boolErr = true;
//                                            anewSta = true;
//                                            reconnectionCount += 1;
//                                            Log.e("recvFalse", "----------returnSta=False-------------");
//                                            socketUtils.clrearBuffer();
//                                            clearLis();
//                                            Thread.sleep(1000);
//                                            socketUtils.clrearBuffer();
//                                            Thread.sleep(500);
//                                            socketUtils.clrearBuffer();
//                                            Thread.sleep(500);
//                                        }
////
//                                    } else {
//                                        System.out.println("---------------socketListener false---  ");
//                                        if (!alarmSta) {
//                                            clearLis();
//                                            socketUtils.clrearBuffer();
//                                            Thread.sleep(1000);
//                                            socketUtils.isReConnect = true;
//                                            socketUtils.releaseSocketNew();
//                                            startMyThread();
//                                            socketUtils.socketReconnection = false;
//                                        }
//                                    }
//                                }
//
//                            }
//
//                        } catch (InterruptedException e) {
//                            // 恢复中断状态
//                            myThread.currentThread().interrupt();
//                            // 清理资源或执行其他必要操作
//                            System.out.println("任务被中断，正在清理资源...");
//                        } catch (IOException e) {
//                            throw new RuntimeException(e);
//                        }
//
//                        rec_count_s = 0;
//                        continue;
//                    }
//                }
//            }
//        }
//    }
//
//    private void startMyThread() {
//        recv_float_bool = true;
//        returnSta = true;
//        receive_one_field_sta = true;
//        boolErr = true;
//    }
//
//    private void stopMyThread() {
//        recv_float_bool = false;
//        returnSta = false;
//        receive_one_field_sta = false;
//        boolErr = false;
//    }
//
//    private void initData() {
//
//        Sends sends = new Sends();
//        Items items = findSelectItem();
//        //sends.setId(1);
//        sends.setItemId(items.getId());
//        sendsService = new SendsService();
//        //sendsService.updade(sends,new Sends());
//        List<Sends> sendlis = sendsService.getSendsLast(sends);
//        if (sendlis.size() > 0) {
//            send_voltage_val.setSelection(Integer.parseInt(sendlis.get(0).getVoltage()));
//            send_repeat_val.setSelection(Integer.parseInt(sendlis.get(0).getRepeatNum()));
//            //send_frequency_val.setText(sendlis.get(0).getSendFrequency());
//            send_frequency_val.setSelection(Integer.parseInt(sendlis.get(0).getSendFrequency()));
//            send_filter_frequency_val.setSelection(Integer.parseInt(sendlis.get(0).getFilterFrequency()));
//            //send_duration_val.setText(sendlis.get(0).getSendDuration());
//            //clear_all_mux_box_connect_val.setText(sendlis.get(0).getBoxaddr());
//        }
//    }
//
//    private Integer findSendCount() {
//        Items items = findSelectItem();
//        sendsService = new SendsService();
//        List<Sends> lis = sendsService.getSends(new Sends(items.getId()));
//        return lis.size();
//    }
//
//    private Integer findItemCount() {
//        itemsService = new ItemsService();
//        List<Items> lis = itemsService.getItems(new Items());
//        return lis.size();
//    }
//
//    private Items findSelectItem() {
//        itemsService = new ItemsService();
//        Items items = new Items();
//        Items items1 = new Items();
//        items.setStatus(1);
//        List<Items> lis = null;
//
//        try {
//            lis = itemsService.getItems(items);
//            items1 = lis.get(0);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return items1;
//    }
//
//    /**
//     * 保存后的弹框
//     */
//    private Boolean showPopupWindow() {
//        //ZloadingUtil.openZloading(myContext);
//
//        //设置contentView
//        contentView = LayoutInflater.from(myContext).inflate(R.layout.send_receive_add_pop, null);
//        mPopWindow = new PopupWindow(contentView,
//                ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, true);
//        mPopWindow.setContentView(contentView);
//        mPopWindow.setTouchable(true); //设置是否响应触摸事件
//        mPopWindow.setFocusable(false);//设置是否能获取焦点（如果控件中药EditText需要设置为true不然无法输入）
//        mPopWindow.setOutsideTouchable(false);
//        setAlpha(0.2f);
//        mChart1 = contentView.findViewById(R.id.send_pop_chart);
//        send_voltage_pop_val = contentView.findViewById(R.id.send_voltage_pop_val);
//        send_repeat_pop_val = contentView.findViewById(R.id.send_repeat_pop_val);
//        send_freq_pop_val = contentView.findViewById(R.id.send_freq_pop_val);
//        receive_duration_pop_val = contentView.findViewById(R.id.receive_duration_pop_val);
//        send_pop_status = contentView.findViewById(R.id.send_pop_status);
//
//        send_voltage_pop_val.setText(svaltage + "v");
//        send_repeat_pop_val.setText(srepeat + "次");
//        send_freq_pop_val.setText(sf + "hz");
//        //receive_duration_pop_val.setText(send_repeat_val.getText() + "秒");
//
//        //显示PopupWindow
//        View rootview = LayoutInflater.from(myContext).inflate(R.layout.send_receive_add, null);
//
//        mPopWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0);
////        mChart1.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                //mPopWindow.setHeight(500);
////                // mPopWindow.showAtLocation(rootview, Gravity.TOP, 0, 0);
////                mChart1.setPivotX(mChart1.getWidth() / 2);
////                mChart1.setPivotY(mChart1.getHeight() / 2);//支点在图片中心
////                mChart1.setRotation(90);
////                ViewGroup.LayoutParams params = mChart1.getLayoutParams();
////                params.width = ScreenUtil.getScreenWidth(myContext);
////                params.height = ScreenUtil.getScreenHeight(myContext);
////                mChart1.setLayoutParams(params);
////            }
////        });
//        //viewHolder.set
//        pop_close = contentView.findViewById(R.id.send_pop_close);
//        pop_close.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (startCount == 1) {
//                    AlertDialog.Builder dialog = new AlertDialog.Builder(myContext);//通过AlertDialog.Builder创建出一个AlertDialog的实例
//
//                    dialog.setTitle("提示");//设置对话框的标题
//                    dialog.setMessage("采集数据中请勿离开页面,否则会中断采集!");//设置对话框的内容
//                    dialog.setCancelable(false);//设置对话框是否可以取消
//                    dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {//确定按钮的点击事件
//
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            try {
//                                Thread.sleep(2000);
//                            } catch (InterruptedException e) {
//                                throw new RuntimeException(e);
//                            }
//                            recv_float_bool = false;
//                            receive_one_field_sta = false;
//                            SocketMergeCallBackUtils.success_count = 0;
//                            mPopWindow.dismiss();
//                            myThread.interrupt();
//                            dtypelen = 0;
//                            dtypelen0 = 0;
//                            setAlpha(1.0f);
//                            SendReceiveAddBeforDianJIActivity.this.finish();
//                        }
//                    });
//                    dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {//取消按钮的点击事件
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            dialog.dismiss();
//                        }
//                    });
//                    dialog.show();//显示对话框
//                } else {
//                    recv_float_bool = false;
//                    receive_one_field_sta = false;
//                    SocketMergeCallBackUtils.success_count = 0;
//                    mPopWindow.dismiss();
//                    setAlpha(1.0f);
//                    SendReceiveAddBeforDianJIActivity.this.finish();
//                }
//
//                SocketMergeCallBackUtils.success_count = 0;
//                try {
//                    queue = null;
//                    data = null;
//                    data2 = null;
//                    data3 = null;
//                    receive_one_field_sta = false;
//                    msg_sueecss_count = 0;
//                    SocketMergeCallBackUtils.packet_indx = 0;
//                    //SocketMergeCallBackUtils.buffer = null;
//                    //SocketMergeCallBackUtils.writeMsg("22,M;");
//
//                    //111
//                    Thread.sleep(10);
//                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                }
//                //Toast.makeText(myContext, "关闭 === " + v.getId(), Toast.LENGTH_SHORT).show();
//
////                SocketMergeCallBackUtils.releaseSocket();
////                socketUtils = null;
//                SocketMergeCallBackUtils.receiveDataAll = "";
//
//
//            }
//        });
//
//        //把背景还原
//        mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//                SocketMergeCallBackUtils.success_count = 5;
//                setAlpha(1.0f);
//            }
//        });
//        return true;
//    }
//
////    private void setImageVal(String tx_voltage) {
////        //final ViewHolder viewHolder;
////        bytesData = null;
////        bytesData = pyobj.callAttr("sendCurve", tx_voltage).toJava(byte[].class);
////        mChart1.setImageBitmap(BitmapFactory.decodeByteArray(bytesData, 0, bytesData.length));
////    }
//
//    private void initPython(Context myContext) throws JSONException, InterruptedException {
//        //初始化python环境
//        if (!Python.isStarted()) {
//            Python.start(new AndroidPlatform(myContext));
//        }
//
//        py = Python.getInstance();
//        //调用hello_python.py里面的plot函式
//        pyobj = py.getModule("plotmy");
//        pyobj1 = py.getModule("Send_Param");
//        pyobj2 = py.getModule("Struct_Data");
//        pyobj3 = py.getModule("earth_main");
//        pyobjfft = py.getModule("fft_ui");
//
//    }
//
//    private void setAlpha(float f) {
//        WindowManager.LayoutParams lp = getWindow().getAttributes();
//        lp.alpha = f;
//        getWindow().setAttributes(lp);
//    }
//
//    public class ViewHolder {
//
//        public ImageView mChart1;
//
//        public ViewHolder(View view, int position) {
//            mChart1 = view.findViewById(R.id.send_pop_chart);
//
//        }
//
//    }
//
//
//}